@tambo-ai/react 0.37.2 → 0.38.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 (75) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/model/tambo-interactable.d.ts +24 -0
  6. package/dist/model/tambo-interactable.d.ts.map +1 -0
  7. package/dist/model/tambo-interactable.js +3 -0
  8. package/dist/model/tambo-interactable.js.map +1 -0
  9. package/dist/providers/__tests__/tambo-prop-stream-provider.test.d.ts +2 -0
  10. package/dist/providers/__tests__/tambo-prop-stream-provider.test.d.ts.map +1 -0
  11. package/dist/providers/__tests__/tambo-prop-stream-provider.test.js +278 -0
  12. package/dist/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -0
  13. package/dist/providers/__tests__/tambo-thread-provider.test.js +7 -0
  14. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  15. package/dist/providers/hoc/with-tambo-interactable.d.ts +34 -0
  16. package/dist/providers/hoc/with-tambo-interactable.d.ts.map +1 -0
  17. package/dist/providers/hoc/with-tambo-interactable.js +119 -0
  18. package/dist/providers/hoc/with-tambo-interactable.js.map +1 -0
  19. package/dist/providers/index.d.ts +1 -0
  20. package/dist/providers/index.d.ts.map +1 -1
  21. package/dist/providers/index.js +3 -1
  22. package/dist/providers/index.js.map +1 -1
  23. package/dist/providers/tambo-interactable-provider.d.ts +20 -0
  24. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -0
  25. package/dist/providers/tambo-interactable-provider.js +243 -0
  26. package/dist/providers/tambo-interactable-provider.js.map +1 -0
  27. package/dist/providers/tambo-prop-stream-provider.d.ts +96 -0
  28. package/dist/providers/tambo-prop-stream-provider.d.ts.map +1 -0
  29. package/dist/providers/tambo-prop-stream-provider.js +185 -0
  30. package/dist/providers/tambo-prop-stream-provider.js.map +1 -0
  31. package/dist/providers/tambo-provider.d.ts +6 -4
  32. package/dist/providers/tambo-provider.d.ts.map +1 -1
  33. package/dist/providers/tambo-provider.js +9 -4
  34. package/dist/providers/tambo-provider.js.map +1 -1
  35. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  36. package/dist/providers/tambo-thread-provider.js +14 -0
  37. package/dist/providers/tambo-thread-provider.js.map +1 -1
  38. package/esm/index.d.ts +4 -1
  39. package/esm/index.d.ts.map +1 -1
  40. package/esm/index.js +3 -1
  41. package/esm/index.js.map +1 -1
  42. package/esm/model/tambo-interactable.d.ts +24 -0
  43. package/esm/model/tambo-interactable.d.ts.map +1 -0
  44. package/esm/model/tambo-interactable.js +2 -0
  45. package/esm/model/tambo-interactable.js.map +1 -0
  46. package/esm/providers/__tests__/tambo-prop-stream-provider.test.d.ts +2 -0
  47. package/esm/providers/__tests__/tambo-prop-stream-provider.test.d.ts.map +1 -0
  48. package/esm/providers/__tests__/tambo-prop-stream-provider.test.js +273 -0
  49. package/esm/providers/__tests__/tambo-prop-stream-provider.test.js.map +1 -0
  50. package/esm/providers/__tests__/tambo-thread-provider.test.js +7 -0
  51. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  52. package/esm/providers/hoc/with-tambo-interactable.d.ts +34 -0
  53. package/esm/providers/hoc/with-tambo-interactable.d.ts.map +1 -0
  54. package/esm/providers/hoc/with-tambo-interactable.js +83 -0
  55. package/esm/providers/hoc/with-tambo-interactable.js.map +1 -0
  56. package/esm/providers/index.d.ts +1 -0
  57. package/esm/providers/index.d.ts.map +1 -1
  58. package/esm/providers/index.js +1 -0
  59. package/esm/providers/index.js.map +1 -1
  60. package/esm/providers/tambo-interactable-provider.d.ts +20 -0
  61. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -0
  62. package/esm/providers/tambo-interactable-provider.js +205 -0
  63. package/esm/providers/tambo-interactable-provider.js.map +1 -0
  64. package/esm/providers/tambo-prop-stream-provider.d.ts +96 -0
  65. package/esm/providers/tambo-prop-stream-provider.d.ts.map +1 -0
  66. package/esm/providers/tambo-prop-stream-provider.js +148 -0
  67. package/esm/providers/tambo-prop-stream-provider.js.map +1 -0
  68. package/esm/providers/tambo-provider.d.ts +6 -4
  69. package/esm/providers/tambo-provider.d.ts.map +1 -1
  70. package/esm/providers/tambo-provider.js +9 -4
  71. package/esm/providers/tambo-provider.js.map +1 -1
  72. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  73. package/esm/providers/tambo-thread-provider.js +14 -0
  74. package/esm/providers/tambo-thread-provider.js.map +1 -1
  75. package/package.json +2 -2
@@ -0,0 +1,83 @@
1
+ // react-sdk/src/providers/with-interactable.tsx
2
+ "use client";
3
+ import React, { useCallback, useEffect, useRef, useState } from "react";
4
+ import { useTamboInteractable } from "../tambo-interactable-provider";
5
+ /**
6
+ * Higher-Order Component that makes any component interactable by tambo.
7
+ * @param WrappedComponent - The component to make interactable
8
+ * @param config - Configuration for the interactable component
9
+ * @returns A new component that is automatically registered as interactable
10
+ * @example
11
+ * ```tsx
12
+ * const MyInteractableNote = withTamboInteractable(MyNote, {
13
+ * componentName: "MyNote",
14
+ * description: "A note component",
15
+ * propsSchema: z.object({
16
+ * title: z.string(),
17
+ * content: z.string(),
18
+ * }),
19
+ * });
20
+ *
21
+ * // Usage
22
+ * <MyInteractableNote title="My Note" content="This is my note" />
23
+ * ```
24
+ */
25
+ export function withTamboInteractable(WrappedComponent, config) {
26
+ const displayName = WrappedComponent.displayName ?? WrappedComponent.name ?? "Component";
27
+ const TamboInteractableWrapper = (props) => {
28
+ const { addInteractableComponent, updateInteractableComponentProps, getInteractableComponent, } = useTamboInteractable();
29
+ const [interactableId, setInteractableId] = useState(null);
30
+ const isInitialized = useRef(false);
31
+ const lastParentProps = useRef({});
32
+ // Extract interactable-specific props
33
+ const { onInteractableReady, onPropsUpdate, ...componentProps } = props;
34
+ // Get the current interactable component to track prop updates
35
+ const currentInteractable = interactableId
36
+ ? getInteractableComponent(interactableId)
37
+ : null;
38
+ // Use the props from the interactable component if available, otherwise use the passed props
39
+ // We need to be careful not to create a loop, so we only use stored props if they're different from passed props
40
+ const effectiveProps = currentInteractable?.props ?? componentProps;
41
+ // Memoize the registration function
42
+ const registerComponent = useCallback(() => {
43
+ if (!isInitialized.current) {
44
+ const id = addInteractableComponent({
45
+ name: config.componentName,
46
+ description: config.description,
47
+ component: WrappedComponent,
48
+ props: componentProps,
49
+ propsSchema: config.propsSchema,
50
+ });
51
+ setInteractableId(id);
52
+ onInteractableReady?.(id);
53
+ isInitialized.current = true;
54
+ }
55
+ }, [addInteractableComponent, componentProps, onInteractableReady]);
56
+ // Register the component as interactable on mount (only once)
57
+ useEffect(() => {
58
+ registerComponent();
59
+ }, [registerComponent]);
60
+ // Update the interactable component when props change from parent
61
+ useEffect(() => {
62
+ if (interactableId && isInitialized.current) {
63
+ // Only update if the props are different from what we last sent
64
+ const lastPropsString = JSON.stringify(lastParentProps.current);
65
+ const currentPropsString = JSON.stringify(componentProps);
66
+ if (lastPropsString !== currentPropsString) {
67
+ updateInteractableComponentProps(interactableId, componentProps);
68
+ onPropsUpdate?.(componentProps);
69
+ lastParentProps.current = componentProps;
70
+ }
71
+ }
72
+ }, [
73
+ interactableId,
74
+ componentProps,
75
+ updateInteractableComponentProps,
76
+ onPropsUpdate,
77
+ ]);
78
+ return React.createElement(WrappedComponent, { ...effectiveProps });
79
+ };
80
+ TamboInteractableWrapper.displayName = `withTamboInteractable(${displayName})`;
81
+ return TamboInteractableWrapper;
82
+ }
83
+ //# sourceMappingURL=with-tambo-interactable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-tambo-interactable.js","sourceRoot":"","sources":["../../../src/providers/hoc/with-tambo-interactable.tsx"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,g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B,EAAE,CAAC,EAAE,CAAC,CAAC;gBAC1B,aAAa,CAAC,OAAO,GAAG,IAAI,CAAC;YAC/B,CAAC;QACH,CAAC,EAAE,CAAC,wBAAwB,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC,CAAC;QAEpE,8DAA8D;QAC9D,SAAS,CAAC,GAAG,EAAE;YACb,iBAAiB,EAAE,CAAC;QACtB,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAExB,kEAAkE;QAClE,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,cAAc,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;gBAC5C,gEAAgE;gBAChE,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;gBAChE,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;gBAE1D,IAAI,eAAe,KAAK,kBAAkB,EAAE,CAAC;oBAC3C,gCAAgC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;oBACjE,aAAa,EAAE,CAAC,cAAc,CAAC,CAAC;oBAChC,eAAe,CAAC,OAAO,GAAG,cAAc,CAAC;gBAC3C,CAAC;YACH,CAAC;QACH,CAAC,EAAE;YACD,cAAc;YACd,cAAc;YACd,gCAAgC;YAChC,aAAa;SACd,CAAC,CAAC;QAEH,OAAO,oBAAC,gBAAgB,OAAM,cAAoB,GAAI,CAAC;IACzD,CAAC,CAAC;IAEF,wBAAwB,CAAC,WAAW,GAAG,yBAAyB,WAAW,GAAG,CAAC;IAE/E,OAAO,wBAAwB,CAAC;AAClC,CAAC","sourcesContent":["// react-sdk/src/providers/with-interactable.tsx\n\"use client\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { z } from \"zod\";\nimport { useTamboInteractable } from \"../tambo-interactable-provider\";\n\nexport interface InteractableConfig {\n componentName: string;\n description: string;\n propsSchema?: z.ZodTypeAny;\n}\n\nexport interface WithTamboInteractableProps {\n interactableId?: string;\n onInteractableReady?: (id: string) => void;\n onPropsUpdate?: (newProps: Record<string, any>) => void;\n}\n\n/**\n * Higher-Order Component that makes any component interactable by tambo.\n * @param WrappedComponent - The component to make interactable\n * @param config - Configuration for the interactable component\n * @returns A new component that is automatically registered as interactable\n * @example\n * ```tsx\n * const MyInteractableNote = withTamboInteractable(MyNote, {\n * componentName: \"MyNote\",\n * description: \"A note component\",\n * propsSchema: z.object({\n * title: z.string(),\n * content: z.string(),\n * }),\n * });\n *\n * // Usage\n * <MyInteractableNote title=\"My Note\" content=\"This is my note\" />\n * ```\n */\nexport function withTamboInteractable<P extends object>(\n WrappedComponent: React.ComponentType<P>,\n config: InteractableConfig,\n) {\n const displayName =\n WrappedComponent.displayName ?? WrappedComponent.name ?? \"Component\";\n\n const TamboInteractableWrapper: React.FC<P & WithTamboInteractableProps> = (\n props,\n ) => {\n const {\n addInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n } = useTamboInteractable();\n\n const [interactableId, setInteractableId] = useState<string | null>(null);\n const isInitialized = useRef(false);\n const lastParentProps = useRef<Record<string, any>>({});\n\n // Extract interactable-specific props\n const { onInteractableReady, onPropsUpdate, ...componentProps } =\n props as P & WithTamboInteractableProps;\n\n // Get the current interactable component to track prop updates\n const currentInteractable = interactableId\n ? getInteractableComponent(interactableId)\n : null;\n\n // Use the props from the interactable component if available, otherwise use the passed props\n // We need to be careful not to create a loop, so we only use stored props if they're different from passed props\n const effectiveProps = currentInteractable?.props ?? componentProps;\n\n // Memoize the registration function\n const registerComponent = useCallback(() => {\n if (!isInitialized.current) {\n const id = addInteractableComponent({\n name: config.componentName,\n description: config.description,\n component: WrappedComponent,\n props: componentProps,\n propsSchema: config.propsSchema,\n });\n\n setInteractableId(id);\n onInteractableReady?.(id);\n isInitialized.current = true;\n }\n }, [addInteractableComponent, componentProps, onInteractableReady]);\n\n // Register the component as interactable on mount (only once)\n useEffect(() => {\n registerComponent();\n }, [registerComponent]);\n\n // Update the interactable component when props change from parent\n useEffect(() => {\n if (interactableId && isInitialized.current) {\n // Only update if the props are different from what we last sent\n const lastPropsString = JSON.stringify(lastParentProps.current);\n const currentPropsString = JSON.stringify(componentProps);\n\n if (lastPropsString !== currentPropsString) {\n updateInteractableComponentProps(interactableId, componentProps);\n onPropsUpdate?.(componentProps);\n lastParentProps.current = componentProps;\n }\n }\n }, [\n interactableId,\n componentProps,\n updateInteractableComponentProps,\n onPropsUpdate,\n ]);\n\n return <WrappedComponent {...(effectiveProps as P)} />;\n };\n\n TamboInteractableWrapper.displayName = `withTamboInteractable(${displayName})`;\n\n return TamboInteractableWrapper;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  export type { TamboComponent, TamboTool } from "../model/component-metadata";
2
2
  export { TamboClientProvider, useTamboClient } from "./tambo-client-provider";
3
3
  export { TamboComponentProvider, useTamboComponent, } from "./tambo-component-provider";
4
+ export { TamboPropStreamProvider } from "./tambo-prop-stream-provider";
4
5
  export { TamboContext, TamboProvider, useTambo } from "./tambo-provider";
5
6
  export { TamboRegistryProvider, useTamboRegistry, type TamboRegistryContext, } from "./tambo-registry-provider";
6
7
  export { TamboStubProvider, type TamboStubProviderProps } from "./tambo-stubs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { TamboClientProvider, useTamboClient } from "./tambo-client-provider";
2
2
  export { TamboComponentProvider, useTamboComponent, } from "./tambo-component-provider";
3
+ export { TamboPropStreamProvider } from "./tambo-prop-stream-provider";
3
4
  export { TamboContext, TamboProvider, useTambo } from "./tambo-provider";
4
5
  export { TamboRegistryProvider, useTamboRegistry, } from "./tambo-registry-provider";
5
6
  export { TamboStubProvider } from "./tambo-stubs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA+B,MAAM,eAAe,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC","sourcesContent":["export type { TamboComponent, TamboTool } from \"../model/component-metadata\";\nexport { TamboClientProvider, useTamboClient } from \"./tambo-client-provider\";\nexport {\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nexport { TamboContext, TamboProvider, useTambo } from \"./tambo-provider\";\nexport {\n TamboRegistryProvider,\n useTamboRegistry,\n type TamboRegistryContext,\n} from \"./tambo-registry-provider\";\nexport { TamboStubProvider, type TamboStubProviderProps } from \"./tambo-stubs\";\nexport {\n TamboThreadContext,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA+B,MAAM,eAAe,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC","sourcesContent":["export type { TamboComponent, TamboTool } from \"../model/component-metadata\";\nexport { TamboClientProvider, useTamboClient } from \"./tambo-client-provider\";\nexport {\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nexport { TamboPropStreamProvider } from \"./tambo-prop-stream-provider\";\nexport { TamboContext, TamboProvider, useTambo } from \"./tambo-provider\";\nexport {\n TamboRegistryProvider,\n useTamboRegistry,\n type TamboRegistryContext,\n} from \"./tambo-registry-provider\";\nexport { TamboStubProvider, type TamboStubProviderProps } from \"./tambo-stubs\";\nexport {\n TamboThreadContext,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n"]}
@@ -0,0 +1,20 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { type TamboInteractableContext } from "../model/tambo-interactable";
3
+ declare const TamboInteractableContext: React.Context<TamboInteractableContext>;
4
+ /**
5
+ * The TamboInteractableProvider manages a list of components that are currently
6
+ * interactable, allowing tambo to interact with them by updating their props. It also registers tools
7
+ * for Tambo to perform CRUD operations on the components list.
8
+ * @param props - The props for the TamboInteractableProvider
9
+ * @param props.children - The children to wrap
10
+ * @returns The TamboInteractableProvider component
11
+ */
12
+ export declare const TamboInteractableProvider: React.FC<PropsWithChildren>;
13
+ /**
14
+ * The useTamboInteractable hook provides access to the interactable component
15
+ * management functions.
16
+ * @returns The interactable component management functions
17
+ */
18
+ export declare const useTamboInteractable: () => TamboInteractableContext;
19
+ export {};
20
+ //# sourceMappingURL=tambo-interactable-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactable-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAGrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4PjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC"}
@@ -0,0 +1,205 @@
1
+ // react-sdk/src/providers/tambo-interactable-provider.tsx
2
+ "use client";
3
+ import React, { createContext, useCallback, useContext, useEffect, useState, } from "react";
4
+ import { z } from "zod";
5
+ import { useTamboComponent } from "./tambo-component-provider";
6
+ const TamboInteractableContext = createContext({
7
+ interactableComponents: [],
8
+ addInteractableComponent: () => "",
9
+ removeInteractableComponent: () => { },
10
+ updateInteractableComponentProps: () => { },
11
+ getInteractableComponent: () => undefined,
12
+ getInteractableComponentsByName: () => [],
13
+ clearAllInteractableComponents: () => { },
14
+ });
15
+ /**
16
+ * The TamboInteractableProvider manages a list of components that are currently
17
+ * interactable, allowing tambo to interact with them by updating their props. It also registers tools
18
+ * for Tambo to perform CRUD operations on the components list.
19
+ * @param props - The props for the TamboInteractableProvider
20
+ * @param props.children - The children to wrap
21
+ * @returns The TamboInteractableProvider component
22
+ */
23
+ export const TamboInteractableProvider = ({ children, }) => {
24
+ const [interactableComponents, setInteractableComponents] = useState([]);
25
+ const { registerTool } = useTamboComponent();
26
+ useEffect(() => {
27
+ registerTool({
28
+ name: "get_all_interactable_components",
29
+ description: "Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.",
30
+ tool: () => {
31
+ return {
32
+ components: interactableComponents,
33
+ };
34
+ },
35
+ toolSchema: z.function().returns(z.object({
36
+ components: z.array(z.object({
37
+ id: z.string(),
38
+ componentName: z.string(),
39
+ props: z.record(z.any()),
40
+ propsSchema: z.object({}).optional(),
41
+ })),
42
+ })),
43
+ });
44
+ registerTool({
45
+ name: "get_interactable_component_by_id",
46
+ description: "Get a specific interactable component by its ID",
47
+ tool: (componentId) => {
48
+ const component = interactableComponents.find((c) => c.id === componentId);
49
+ if (!component) {
50
+ return {
51
+ success: false,
52
+ error: `Component with ID ${componentId} not found`,
53
+ };
54
+ }
55
+ return {
56
+ success: true,
57
+ component: {
58
+ id: component.id,
59
+ componentName: component.name,
60
+ props: component.props,
61
+ },
62
+ };
63
+ },
64
+ toolSchema: z
65
+ .function()
66
+ .args(z.string())
67
+ .returns(z.object({
68
+ success: z.boolean(),
69
+ component: z
70
+ .object({
71
+ id: z.string(),
72
+ componentName: z.string(),
73
+ props: z.record(z.any()),
74
+ })
75
+ .optional(),
76
+ error: z.string().optional(),
77
+ })),
78
+ });
79
+ registerTool({
80
+ name: "remove_interactable_component",
81
+ description: "Remove an interactable component from the system",
82
+ tool: (componentId) => {
83
+ const component = interactableComponents.find((c) => c.id === componentId);
84
+ if (!component) {
85
+ return {
86
+ success: false,
87
+ error: `Component with ID ${componentId} not found`,
88
+ };
89
+ }
90
+ setInteractableComponents((prev) => prev.filter((c) => c.id !== componentId));
91
+ return {
92
+ success: true,
93
+ componentId,
94
+ removedComponent: {
95
+ id: component.id,
96
+ componentName: component.name,
97
+ props: component.props,
98
+ },
99
+ };
100
+ },
101
+ toolSchema: z
102
+ .function()
103
+ .args(z.string())
104
+ .returns(z.object({
105
+ success: z.boolean(),
106
+ componentId: z.string(),
107
+ removedComponent: z.object({
108
+ id: z.string(),
109
+ componentName: z.string(),
110
+ props: z.record(z.any()),
111
+ }),
112
+ error: z.string().optional(),
113
+ })),
114
+ });
115
+ }, [interactableComponents, registerTool]);
116
+ const updateInteractableComponentProps = useCallback((id, newProps) => {
117
+ let updateResult = "Updated successfully";
118
+ setInteractableComponents((prev) => {
119
+ const componentExists = prev.some((c) => c.id === id);
120
+ if (!componentExists) {
121
+ updateResult = `Error: Component with ID ${id} not found`;
122
+ return prev;
123
+ }
124
+ const updatedComponents = prev.map((c) => c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c);
125
+ // Check if the update actually changed anything
126
+ const originalComponent = prev.find((c) => c.id === id);
127
+ const updatedComponent = updatedComponents.find((c) => c.id === id);
128
+ if (!originalComponent || !updatedComponent) {
129
+ updateResult = `Error: Failed to update component with ID ${id}`;
130
+ return prev;
131
+ }
132
+ // Check if props actually changed
133
+ const propsChanged = JSON.stringify(originalComponent.props) !==
134
+ JSON.stringify(updatedComponent.props);
135
+ if (!propsChanged) {
136
+ updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;
137
+ return prev;
138
+ }
139
+ return updatedComponents;
140
+ });
141
+ return updateResult;
142
+ }, []);
143
+ const registerInteractableComponentUpdateTool = useCallback((component) => {
144
+ const schemaForArgs = typeof component.propsSchema === "object" &&
145
+ "describe" in component.propsSchema
146
+ ? component.propsSchema
147
+ : z.object({});
148
+ registerTool({
149
+ name: `update_interactable_component_${component.id}`,
150
+ description: `Update the props of interactable component ${component.id} (${component.name})`,
151
+ tool: (componentId, newProps) => {
152
+ return updateInteractableComponentProps(componentId, newProps);
153
+ },
154
+ toolSchema: z
155
+ .function()
156
+ .args(z
157
+ .string()
158
+ .describe("The ID of the interactable component to update"), schemaForArgs.describe("The new props to update the component with"))
159
+ .returns(z.string()),
160
+ });
161
+ }, [registerTool, updateInteractableComponentProps]);
162
+ const addInteractableComponent = useCallback((component) => {
163
+ const id = `${component.name}-${Math.random().toString(36).substr(2, 9)}`;
164
+ const newComponent = {
165
+ ...component,
166
+ id,
167
+ };
168
+ registerInteractableComponentUpdateTool(newComponent);
169
+ setInteractableComponents((prev) => {
170
+ return [...prev, newComponent];
171
+ });
172
+ return id;
173
+ }, [registerInteractableComponentUpdateTool]);
174
+ const removeInteractableComponent = useCallback((id) => {
175
+ setInteractableComponents((prev) => prev.filter((c) => c.id !== id));
176
+ }, []);
177
+ const getInteractableComponent = useCallback((id) => {
178
+ return interactableComponents.find((c) => c.id === id);
179
+ }, [interactableComponents]);
180
+ const getInteractableComponentsByName = useCallback((componentName) => {
181
+ return interactableComponents.filter((c) => c.name === componentName);
182
+ }, [interactableComponents]);
183
+ const clearAllInteractableComponents = useCallback(() => {
184
+ setInteractableComponents([]);
185
+ }, []);
186
+ const value = {
187
+ interactableComponents,
188
+ addInteractableComponent,
189
+ removeInteractableComponent,
190
+ updateInteractableComponentProps,
191
+ getInteractableComponent,
192
+ getInteractableComponentsByName,
193
+ clearAllInteractableComponents,
194
+ };
195
+ return (React.createElement(TamboInteractableContext.Provider, { value: value }, children));
196
+ };
197
+ /**
198
+ * The useTamboInteractable hook provides access to the interactable component
199
+ * management functions.
200
+ * @returns The interactable component management functions
201
+ */
202
+ export const useTamboInteractable = () => {
203
+ return useContext(TamboInteractableContext);
204
+ };
205
+ //# sourceMappingURL=tambo-interactable-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,wBAAwB,GAAG,aAAa,CAA2B;IACvE,sBAAsB,EAAE,EAAE;IAC1B,wBAAwB,EAAE,GAAG,EAAE,CAAC,EAAE;IAClC,2BAA2B,EAAE,GAAG,EAAE,GAAE,CAAC;IACrC,gCAAgC,EAAE,GAAG,EAAE,GAAE,CAAC;IAC1C,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS;IACzC,+BAA+B,EAAE,GAAG,EAAE,CAAC,EAAE;IACzC,8BAA8B,EAAE,GAAG,EAAE,GAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAgC,CAAC,EACrE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,QAAQ,CAElE,EAAE,CAAC,CAAC;IACN,MAAM,EAAE,YAAY,EAAE,GAAG,iBAAiB,EAAE,CAAC;I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AAU,EAAE,EAAE;QACb,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC,EACD,CAAC,sBAAsB,CAAC,CACzB,CAAC;IAEF,MAAM,+BAA+B,GAAG,WAAW,CACjD,CAAC,aAAqB,EAAE,EAAE;QACxB,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;IACxE,CAAC,EACD,CAAC,sBAAsB,CAAC,CACzB,CAAC;IAEF,MAAM,8BAA8B,GAAG,WAAW,CAAC,GAAG,EAAE;QACtD,yBAAyB,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAA6B;QACtC,sBAAsB;QACtB,wBAAwB;QACxB,2BAA2B;QAC3B,gCAAgC;QAChC,wBAAwB;QACxB,+BAA+B;QAC/B,8BAA8B;KAC/B,CAAC;IAEF,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["// react-sdk/src/providers/tambo-interactable-provider.tsx\n\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-provider\";\n\nconst TamboInteractableContext = createContext<TamboInteractableContext>({\n interactableComponents: [],\n addInteractableComponent: () => \"\",\n removeInteractableComponent: () => {},\n updateInteractableComponentProps: () => {},\n getInteractableComponent: () => undefined,\n getInteractableComponentsByName: () => [],\n clearAllInteractableComponents: () => {},\n});\n\n/**\n * The TamboInteractableProvider manages a list of components that are currently\n * interactable, allowing tambo to interact with them by updating their props. It also registers tools\n * for Tambo to perform CRUD operations on the components list.\n * @param props - The props for the TamboInteractableProvider\n * @param props.children - The children to wrap\n * @returns The TamboInteractableProvider component\n */\nexport const TamboInteractableProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [interactableComponents, setInteractableComponents] = useState<\n TamboInteractableComponent[]\n >([]);\n const { registerTool } = useTamboComponent();\n\n useEffect(() => {\n registerTool({\n name: \"get_all_interactable_components\",\n description:\n \"Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.\",\n tool: () => {\n return {\n components: interactableComponents,\n };\n },\n toolSchema: z.function().returns(\n z.object({\n components: z.array(\n z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n propsSchema: z.object({}).optional(),\n }),\n ),\n }),\n ),\n });\n\n registerTool({\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n })\n .optional(),\n error: z.string().optional(),\n }),\n ),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n setInteractableComponents((prev) =>\n prev.filter((c) => c.id !== componentId),\n );\n\n return {\n success: true,\n componentId,\n removedComponent: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n }),\n error: z.string().optional(),\n }),\n ),\n });\n }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>) => {\n let updateResult = \"Updated successfully\";\n\n setInteractableComponents((prev) => {\n const componentExists = prev.some((c) => c.id === id);\n\n if (!componentExists) {\n updateResult = `Error: Component with ID ${id} not found`;\n return prev;\n }\n\n const updatedComponents = prev.map((c) =>\n c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c,\n );\n\n // Check if the update actually changed anything\n const originalComponent = prev.find((c) => c.id === id);\n const updatedComponent = updatedComponents.find((c) => c.id === id);\n\n if (!originalComponent || !updatedComponent) {\n updateResult = `Error: Failed to update component with ID ${id}`;\n return prev;\n }\n\n // Check if props actually changed\n const propsChanged =\n JSON.stringify(originalComponent.props) !==\n JSON.stringify(updatedComponent.props);\n\n if (!propsChanged) {\n updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;\n return prev;\n }\n\n return updatedComponents;\n });\n\n return updateResult;\n },\n [],\n );\n\n const registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent) => {\n const schemaForArgs =\n typeof component.propsSchema === \"object\" &&\n \"describe\" in component.propsSchema\n ? component.propsSchema\n : z.object({});\n\n registerTool({\n name: `update_interactable_component_${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name})`,\n tool: (componentId: string, newProps: any) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n toolSchema: z\n .function()\n .args(\n z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n schemaForArgs.describe(\n \"The new props to update the component with\",\n ),\n )\n .returns(z.string()),\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n const id = `${component.name}-${Math.random().toString(36).substr(2, 9)}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n };\n\n registerInteractableComponentUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [registerInteractableComponentUpdateTool],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n (id: string) => {\n return interactableComponents.find((c) => c.id === id);\n },\n [interactableComponents],\n );\n\n const getInteractableComponentsByName = useCallback(\n (componentName: string) => {\n return interactableComponents.filter((c) => c.name === componentName);\n },\n [interactableComponents],\n );\n\n const clearAllInteractableComponents = useCallback(() => {\n setInteractableComponents([]);\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n };\n\n return (\n <TamboInteractableContext.Provider value={value}>\n {children}\n </TamboInteractableContext.Provider>\n );\n};\n\n/**\n * The useTamboInteractable hook provides access to the interactable component\n * management functions.\n * @returns The interactable component management functions\n */\nexport const useTamboInteractable = () => {\n return useContext(TamboInteractableContext);\n};\n"]}
@@ -0,0 +1,96 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { StreamStatus } from "../hooks/use-tambo-stream-status";
3
+ interface TamboPropStreamContextValue {
4
+ /** The stream data */
5
+ data: any;
6
+ /** The stream status */
7
+ streamStatus: StreamStatus;
8
+ /** Get the status for a specific key */
9
+ getStatusForKey: (key: string) => {
10
+ isPending: boolean;
11
+ isStreaming: boolean;
12
+ isSuccess: boolean;
13
+ isError: boolean;
14
+ error?: Error;
15
+ };
16
+ }
17
+ export interface TamboPropStreamProviderProps {
18
+ /** The stream data */
19
+ data: any;
20
+ /** Optional stream status for more granular control */
21
+ streamStatus?: StreamStatus;
22
+ }
23
+ export interface LoadingProps {
24
+ /** The key to identify this loading state */
25
+ streamKey?: string;
26
+ /** The children to render when loading */
27
+ children: React.ReactNode;
28
+ /** Optional className for styling */
29
+ className?: string;
30
+ }
31
+ export interface EmptyProps {
32
+ /** The key to identify this empty state */
33
+ streamKey?: string;
34
+ /** The children to render when empty */
35
+ children: React.ReactNode;
36
+ /** Optional className for styling */
37
+ className?: string;
38
+ }
39
+ export interface CompleteProps {
40
+ /** The key to identify this complete state */
41
+ streamKey?: string;
42
+ /** The children to render when complete */
43
+ children: React.ReactNode;
44
+ /** Optional className for styling */
45
+ className?: string;
46
+ }
47
+ /**
48
+ * Loading component that renders children when the stream is in a loading state
49
+ * @param props - The props for the Loading component
50
+ * @param props.key - The key to identify this loading state
51
+ * @param props.children - The children to render when loading
52
+ * @param props.className - Optional className for styling
53
+ * @returns The Loading component
54
+ */
55
+ declare const Loading: React.FC<LoadingProps>;
56
+ /**
57
+ * Empty component that renders children when the stream has no data
58
+ * @param props - The props for the Empty component
59
+ * @param props.key - The key to identify this empty state
60
+ * @param props.children - The children to render when empty
61
+ * @param props.className - Optional className for styling
62
+ * @returns The Empty component
63
+ */
64
+ declare const Empty: React.FC<EmptyProps>;
65
+ /**
66
+ * Complete component that renders children when the stream has data
67
+ * @param props - The props for the Complete component
68
+ * @param props.key - The key to identify this complete state
69
+ * @param props.children - The children to render when complete
70
+ * @param props.className - Optional className for styling
71
+ * @returns The Complete component
72
+ */
73
+ declare const Complete: React.FC<CompleteProps>;
74
+ /**
75
+ * Hook to use the TamboStream context
76
+ * @returns The TamboStream context
77
+ */
78
+ export declare const useTamboStream: () => TamboPropStreamContextValue;
79
+ /**
80
+ * The TamboStreamProvider provides a context for managing stream states
81
+ * with compound components for Loading, Empty, and Complete states.
82
+ * @param props - The props for the TamboStreamProvider
83
+ * @param props.children - The children to wrap
84
+ * @param props.data - The stream data
85
+ * @param props.streamStatus - Optional stream status for more granular control
86
+ * @returns The TamboStreamProvider component
87
+ */
88
+ declare const TamboPropStreamProviderComponent: React.FC<PropsWithChildren<TamboPropStreamProviderProps>>;
89
+ type TamboPropStreamProviderCompound = typeof TamboPropStreamProviderComponent & {
90
+ Loading: typeof Loading;
91
+ Empty: typeof Empty;
92
+ Complete: typeof Complete;
93
+ };
94
+ export declare const TamboPropStreamProvider: TamboPropStreamProviderCompound;
95
+ export {};
96
+ //# sourceMappingURL=tambo-prop-stream-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-prop-stream-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-prop-stream-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAGlB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,UAAU,2BAA2B;IACnC,sBAAsB;IACtB,IAAI,EAAE,GAAG,CAAC;IACV,wBAAwB;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,wCAAwC;IACxC,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK;QAChC,SAAS,EAAE,OAAO,CAAC;QACnB,WAAW,EAAE,OAAO,CAAC;QACrB,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;CACH;AAKD,MAAM,WAAW,4BAA4B;IAC3C,sBAAsB;IACtB,IAAI,EAAE,GAAG,CAAC;IACV,uDAAuD;IACvD,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAqBnC,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CAmC/B,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA+BrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,mCAQ1B,CAAC;AAEF;;;;;;;;GAQG;AACH,QAAA,MAAM,gCAAgC,EAAE,KAAK,CAAC,EAAE,CAC9C,iBAAiB,CAAC,4BAA4B,CAAC,CA2FhD,CAAC;AAGF,KAAK,+BAA+B,GAClC,OAAO,gCAAgC,GAAG;IACxC,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC;AAEJ,eAAO,MAAM,uBAAuB,EACE,+BAA+B,CAAC"}
@@ -0,0 +1,148 @@
1
+ "use client";
2
+ import React, { createContext, useContext, useMemo, } from "react";
3
+ const TamboPropStreamContext = createContext(null);
4
+ /**
5
+ * Loading component that renders children when the stream is in a loading state
6
+ * @param props - The props for the Loading component
7
+ * @param props.key - The key to identify this loading state
8
+ * @param props.children - The children to render when loading
9
+ * @param props.className - Optional className for styling
10
+ * @returns The Loading component
11
+ */
12
+ const Loading = ({ streamKey = "default", children, className, }) => {
13
+ const { getStatusForKey } = useTamboStream();
14
+ const status = getStatusForKey(streamKey);
15
+ if (!status.isPending && !status.isStreaming) {
16
+ return null;
17
+ }
18
+ return (React.createElement("div", { className: className, "data-stream-key": streamKey, "data-stream-state": "loading" }, children));
19
+ };
20
+ /**
21
+ * Empty component that renders children when the stream has no data
22
+ * @param props - The props for the Empty component
23
+ * @param props.key - The key to identify this empty state
24
+ * @param props.children - The children to render when empty
25
+ * @param props.className - Optional className for styling
26
+ * @returns The Empty component
27
+ */
28
+ const Empty = ({ streamKey = "default", children, className, }) => {
29
+ const { data, getStatusForKey } = useTamboStream();
30
+ const status = getStatusForKey(streamKey);
31
+ // Get the specific data for this key
32
+ const keyData = data && typeof data === "object" && !Array.isArray(data)
33
+ ? data[streamKey]
34
+ : data;
35
+ // Show empty state when not loading, not streaming, not successful, and no data for this key
36
+ const shouldShowEmpty = !status.isPending &&
37
+ !status.isStreaming &&
38
+ !status.isSuccess &&
39
+ !status.isError &&
40
+ (keyData === undefined || keyData === null || keyData === "");
41
+ if (!shouldShowEmpty) {
42
+ return null;
43
+ }
44
+ return (React.createElement("div", { className: className, "data-stream-key": streamKey, "data-stream-state": "empty" }, children));
45
+ };
46
+ /**
47
+ * Complete component that renders children when the stream has data
48
+ * @param props - The props for the Complete component
49
+ * @param props.key - The key to identify this complete state
50
+ * @param props.children - The children to render when complete
51
+ * @param props.className - Optional className for styling
52
+ * @returns The Complete component
53
+ */
54
+ const Complete = ({ streamKey = "default", children, className, }) => {
55
+ const { data, getStatusForKey } = useTamboStream();
56
+ const status = getStatusForKey(streamKey);
57
+ // Get the specific data for this key
58
+ const keyData = data && typeof data === "object" && !Array.isArray(data)
59
+ ? data[streamKey]
60
+ : data;
61
+ // Show complete when we have data for this key and the stream is successful
62
+ const shouldShowComplete = status.isSuccess && keyData !== undefined && keyData !== null;
63
+ if (!shouldShowComplete) {
64
+ return null;
65
+ }
66
+ return (React.createElement("div", { className: className, "data-stream-key": streamKey, "data-stream-state": "complete" }, children));
67
+ };
68
+ /**
69
+ * Hook to use the TamboStream context
70
+ * @returns The TamboStream context
71
+ */
72
+ export const useTamboStream = () => {
73
+ const context = useContext(TamboPropStreamContext);
74
+ if (!context) {
75
+ throw new Error("useTamboStream must be used within a TamboPropStreamProvider");
76
+ }
77
+ return context;
78
+ };
79
+ /**
80
+ * The TamboStreamProvider provides a context for managing stream states
81
+ * with compound components for Loading, Empty, and Complete states.
82
+ * @param props - The props for the TamboStreamProvider
83
+ * @param props.children - The children to wrap
84
+ * @param props.data - The stream data
85
+ * @param props.streamStatus - Optional stream status for more granular control
86
+ * @returns The TamboStreamProvider component
87
+ */
88
+ const TamboPropStreamProviderComponent = ({ children, data, streamStatus }) => {
89
+ // Create a default stream status if none provided
90
+ const defaultStreamStatus = useMemo(() => ({
91
+ isPending: false, // No external stream, so not pending
92
+ isStreaming: false, // No external stream, so not streaming
93
+ isSuccess: true, // If no stream status provided, assume success
94
+ isError: false,
95
+ streamError: undefined,
96
+ }), []);
97
+ const finalStreamStatus = streamStatus ?? defaultStreamStatus;
98
+ // Track status by key for compound components
99
+ const keyStatusMap = useMemo(() => {
100
+ const map = new Map();
101
+ // Track per-key status based on data structure
102
+ // If data is an object with keys, create status for each key
103
+ if (data && typeof data === "object" && !Array.isArray(data)) {
104
+ Object.keys(data).forEach((key) => {
105
+ const keyData = data[key];
106
+ const hasData = keyData !== undefined && keyData !== null && keyData !== "";
107
+ map.set(key, {
108
+ // If no external stream, show loading when key has no data
109
+ isPending: finalStreamStatus.isPending ||
110
+ (!finalStreamStatus.isStreaming && !hasData),
111
+ isStreaming: finalStreamStatus.isStreaming && !hasData,
112
+ isSuccess: finalStreamStatus.isSuccess && hasData,
113
+ isError: finalStreamStatus.isError,
114
+ error: finalStreamStatus.streamError,
115
+ });
116
+ });
117
+ }
118
+ // Always set default status for fallback
119
+ map.set("default", {
120
+ isPending: finalStreamStatus.isPending,
121
+ isStreaming: finalStreamStatus.isStreaming,
122
+ isSuccess: finalStreamStatus.isSuccess,
123
+ isError: finalStreamStatus.isError,
124
+ error: finalStreamStatus.streamError,
125
+ });
126
+ return map;
127
+ }, [finalStreamStatus, data]);
128
+ const getStatusForKey = useMemo(() => (key) => {
129
+ return (keyStatusMap.get(key) ??
130
+ keyStatusMap.get("default") ?? {
131
+ isPending: false,
132
+ isStreaming: false,
133
+ isSuccess: false,
134
+ isError: false,
135
+ });
136
+ }, [keyStatusMap]);
137
+ const contextValue = useMemo(() => ({
138
+ data,
139
+ streamStatus: finalStreamStatus,
140
+ getStatusForKey,
141
+ }), [data, finalStreamStatus, getStatusForKey]);
142
+ return (React.createElement(TamboPropStreamContext.Provider, { value: contextValue }, children));
143
+ };
144
+ export const TamboPropStreamProvider = TamboPropStreamProviderComponent;
145
+ TamboPropStreamProvider.Loading = Loading;
146
+ TamboPropStreamProvider.Empty = Empty;
147
+ TamboPropStreamProvider.Complete = Complete;
148
+ //# sourceMappingURL=tambo-prop-stream-provider.js.map