@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 @@
1
+ {"version":3,"file":"tambo-prop-stream-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-prop-stream-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAC;AAkBf,MAAM,sBAAsB,GAC1B,aAAa,CAAqC,IAAI,CAAC,CAAC;AAoC1D;;;;;;;GAOG;AACH,MAAM,OAAO,GAA2B,CAAC,EACvC,SAAS,GAAG,SAAS,EACrB,QAAQ,EACR,SAAS,GACV,EAAE,EAAE;IACH,MAAM,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE,CAAC;IAC7C,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAE1C,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,6BACE,SAAS,EAAE,SAAS,qBACH,SAAS,uBACR,SAAS,IAE1B,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,KAAK,GAAyB,CAAC,EACnC,SAAS,GAAG,SAAS,EACrB,QAAQ,EACR,SAAS,GACV,EAAE,EAAE;IACH,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,GA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,CAAC,CACf,CAAC;IAEF,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,YAAY,EAAE,iBAAiB;QAC/B,eAAe;KAChB,CAAC,EACF,CAAC,IAAI,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAC3C,CAAC;IAEF,OAAO,CACL,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IACjD,QAAQ,CACuB,CACnC,CAAC;AACJ,CAAC,CAAC;AAUF,MAAM,CAAC,MAAM,uBAAuB,GAClC,gCAAmE,CAAC;AAEtE,uBAAuB,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1C,uBAAuB,CAAC,KAAK,GAAG,KAAK,CAAC;AACtC,uBAAuB,CAAC,QAAQ,GAAG,QAAQ,CAAC","sourcesContent":["\"use client\";\n\nimport React, {\n createContext,\n PropsWithChildren,\n useContext,\n useMemo,\n} from \"react\";\nimport { StreamStatus } from \"../hooks/use-tambo-stream-status\";\n\ninterface TamboPropStreamContextValue {\n /** The stream data */\n data: any;\n /** The stream status */\n streamStatus: StreamStatus;\n /** Get the status for a specific key */\n getStatusForKey: (key: string) => {\n isPending: boolean;\n isStreaming: boolean;\n isSuccess: boolean;\n isError: boolean;\n error?: Error;\n };\n}\n\nconst TamboPropStreamContext =\n createContext<TamboPropStreamContextValue | null>(null);\n\nexport interface TamboPropStreamProviderProps {\n /** The stream data */\n data: any;\n /** Optional stream status for more granular control */\n streamStatus?: StreamStatus;\n}\n\nexport interface LoadingProps {\n /** The key to identify this loading state */\n streamKey?: string;\n /** The children to render when loading */\n children: React.ReactNode;\n /** Optional className for styling */\n className?: string;\n}\n\nexport interface EmptyProps {\n /** The key to identify this empty state */\n streamKey?: string;\n /** The children to render when empty */\n children: React.ReactNode;\n /** Optional className for styling */\n className?: string;\n}\n\nexport interface CompleteProps {\n /** The key to identify this complete state */\n streamKey?: string;\n /** The children to render when complete */\n children: React.ReactNode;\n /** Optional className for styling */\n className?: string;\n}\n\n/**\n * Loading component that renders children when the stream is in a loading state\n * @param props - The props for the Loading component\n * @param props.key - The key to identify this loading state\n * @param props.children - The children to render when loading\n * @param props.className - Optional className for styling\n * @returns The Loading component\n */\nconst Loading: React.FC<LoadingProps> = ({\n streamKey = \"default\",\n children,\n className,\n}) => {\n const { getStatusForKey } = useTamboStream();\n const status = getStatusForKey(streamKey);\n\n if (!status.isPending && !status.isStreaming) {\n return null;\n }\n\n return (\n <div\n className={className}\n data-stream-key={streamKey}\n data-stream-state=\"loading\"\n >\n {children}\n </div>\n );\n};\n\n/**\n * Empty component that renders children when the stream has no data\n * @param props - The props for the Empty component\n * @param props.key - The key to identify this empty state\n * @param props.children - The children to render when empty\n * @param props.className - Optional className for styling\n * @returns The Empty component\n */\nconst Empty: React.FC<EmptyProps> = ({\n streamKey = \"default\",\n children,\n className,\n}) => {\n const { data, getStatusForKey } = useTamboStream();\n const status = getStatusForKey(streamKey);\n\n // Get the specific data for this key\n const keyData =\n data && typeof data === \"object\" && !Array.isArray(data)\n ? data[streamKey]\n : data;\n\n // Show empty state when not loading, not streaming, not successful, and no data for this key\n const shouldShowEmpty =\n !status.isPending &&\n !status.isStreaming &&\n !status.isSuccess &&\n !status.isError &&\n (keyData === undefined || keyData === null || keyData === \"\");\n\n if (!shouldShowEmpty) {\n return null;\n }\n\n return (\n <div\n className={className}\n data-stream-key={streamKey}\n data-stream-state=\"empty\"\n >\n {children}\n </div>\n );\n};\n\n/**\n * Complete component that renders children when the stream has data\n * @param props - The props for the Complete component\n * @param props.key - The key to identify this complete state\n * @param props.children - The children to render when complete\n * @param props.className - Optional className for styling\n * @returns The Complete component\n */\nconst Complete: React.FC<CompleteProps> = ({\n streamKey = \"default\",\n children,\n className,\n}) => {\n const { data, getStatusForKey } = useTamboStream();\n const status = getStatusForKey(streamKey);\n\n // Get the specific data for this key\n const keyData =\n data && typeof data === \"object\" && !Array.isArray(data)\n ? data[streamKey]\n : data;\n\n // Show complete when we have data for this key and the stream is successful\n const shouldShowComplete =\n status.isSuccess && keyData !== undefined && keyData !== null;\n\n if (!shouldShowComplete) {\n return null;\n }\n\n return (\n <div\n className={className}\n data-stream-key={streamKey}\n data-stream-state=\"complete\"\n >\n {children}\n </div>\n );\n};\n\n/**\n * Hook to use the TamboStream context\n * @returns The TamboStream context\n */\nexport const useTamboStream = () => {\n const context = useContext(TamboPropStreamContext);\n if (!context) {\n throw new Error(\n \"useTamboStream must be used within a TamboPropStreamProvider\",\n );\n }\n return context;\n};\n\n/**\n * The TamboStreamProvider provides a context for managing stream states\n * with compound components for Loading, Empty, and Complete states.\n * @param props - The props for the TamboStreamProvider\n * @param props.children - The children to wrap\n * @param props.data - The stream data\n * @param props.streamStatus - Optional stream status for more granular control\n * @returns The TamboStreamProvider component\n */\nconst TamboPropStreamProviderComponent: React.FC<\n PropsWithChildren<TamboPropStreamProviderProps>\n> = ({ children, data, streamStatus }) => {\n // Create a default stream status if none provided\n const defaultStreamStatus: StreamStatus = useMemo(\n () => ({\n isPending: false, // No external stream, so not pending\n isStreaming: false, // No external stream, so not streaming\n isSuccess: true, // If no stream status provided, assume success\n isError: false,\n streamError: undefined,\n }),\n [],\n );\n\n const finalStreamStatus = streamStatus ?? defaultStreamStatus;\n\n // Track status by key for compound components\n const keyStatusMap = useMemo(() => {\n const map = new Map<\n string,\n {\n isPending: boolean;\n isStreaming: boolean;\n isSuccess: boolean;\n isError: boolean;\n error?: Error;\n }\n >();\n\n // Track per-key status based on data structure\n // If data is an object with keys, create status for each key\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n Object.keys(data).forEach((key) => {\n const keyData = data[key];\n const hasData =\n keyData !== undefined && keyData !== null && keyData !== \"\";\n\n map.set(key, {\n // If no external stream, show loading when key has no data\n isPending:\n finalStreamStatus.isPending ||\n (!finalStreamStatus.isStreaming && !hasData),\n isStreaming: finalStreamStatus.isStreaming && !hasData,\n isSuccess: finalStreamStatus.isSuccess && hasData,\n isError: finalStreamStatus.isError,\n error: finalStreamStatus.streamError,\n });\n });\n }\n\n // Always set default status for fallback\n map.set(\"default\", {\n isPending: finalStreamStatus.isPending,\n isStreaming: finalStreamStatus.isStreaming,\n isSuccess: finalStreamStatus.isSuccess,\n isError: finalStreamStatus.isError,\n error: finalStreamStatus.streamError,\n });\n\n return map;\n }, [finalStreamStatus, data]);\n\n const getStatusForKey = useMemo(\n () => (key: string) => {\n return (\n keyStatusMap.get(key) ??\n keyStatusMap.get(\"default\") ?? {\n isPending: false,\n isStreaming: false,\n isSuccess: false,\n isError: false,\n }\n );\n },\n [keyStatusMap],\n );\n\n const contextValue = useMemo(\n () => ({\n data,\n streamStatus: finalStreamStatus,\n getStatusForKey,\n }),\n [data, finalStreamStatus, getStatusForKey],\n );\n\n return (\n <TamboPropStreamContext.Provider value={contextValue}>\n {children}\n </TamboPropStreamContext.Provider>\n );\n};\n\n// Create the compound component type\ntype TamboPropStreamProviderCompound =\n typeof TamboPropStreamProviderComponent & {\n Loading: typeof Loading;\n Empty: typeof Empty;\n Complete: typeof Complete;\n };\n\nexport const TamboPropStreamProvider =\n TamboPropStreamProviderComponent as TamboPropStreamProviderCompound;\n\nTamboPropStreamProvider.Loading = Loading;\nTamboPropStreamProvider.Empty = Empty;\nTamboPropStreamProvider.Complete = Complete;\n"]}
@@ -1,11 +1,12 @@
1
1
  import React, { PropsWithChildren } from "react";
2
+ import { TamboInteractableContext } from "../model/tambo-interactable";
2
3
  import { TamboClientContextProps, TamboClientProviderProps } from "./tambo-client-provider";
3
4
  import { TamboComponentContextProps } from "./tambo-component-provider";
4
5
  import { TamboRegistryProviderProps } from "./tambo-registry-provider";
5
6
  import { TamboThreadContextProps, TamboThreadProviderProps } from "./tambo-thread-provider";
6
7
  /**
7
8
  * The TamboProvider gives full access to the whole Tambo API. This includes the
8
- * TamboAI client, the component registry, and the current thread context.
9
+ * TamboAI client, the component registry, the current thread context, and interactable components.
9
10
  * @param props - The props for the TamboProvider
10
11
  * @param props.children - The children to wrap
11
12
  * @param props.tamboUrl - The URL of the Tambo API
@@ -17,11 +18,11 @@ import { TamboThreadContextProps, TamboThreadProviderProps } from "./tambo-threa
17
18
  * @returns The TamboProvider component
18
19
  */
19
20
  export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps>>;
20
- export type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboComponentContextProps;
21
+ export type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboComponentContextProps & TamboInteractableContext;
21
22
  export declare const TamboContext: React.Context<TamboContextProps>;
22
23
  /**
23
24
  * TamboCompositeProvider is a provider that combines the TamboClient,
24
- * TamboThread, and TamboComponent providers
25
+ * TamboThread, TamboComponent, and TamboInteractable providers
25
26
  * @param props - The props for the TamboCompositeProvider
26
27
  * @param props.children - The children to wrap
27
28
  * @returns The wrapped component
@@ -31,7 +32,8 @@ export declare const TamboCompositeProvider: React.FC<PropsWithChildren>;
31
32
  * The useTambo hook provides access to the Tambo API. This is the primary entrypoint
32
33
  * for the Tambo React SDK.
33
34
  *
34
- * This includes the TamboAI client, the component registry, and the current thread context.
35
+ * This includes the TamboAI client, the component registry, the current thread context,
36
+ * and interactable component management.
35
37
  * @returns The Tambo API
36
38
  */
37
39
  export declare const useTambo: () => TamboContextProps;
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;G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;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
@@ -2,11 +2,12 @@
2
2
  import React, { createContext, useContext } from "react";
3
3
  import { TamboClientProvider, useTamboClient, useTamboQueryClient, } from "./tambo-client-provider";
4
4
  import { TamboComponentProvider, useTamboComponent, } from "./tambo-component-provider";
5
+ import { TamboInteractableProvider, useTamboInteractable, } from "./tambo-interactable-provider";
5
6
  import { TamboRegistryProvider, } from "./tambo-registry-provider";
6
7
  import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
7
8
  /**
8
9
  * The TamboProvider gives full access to the whole Tambo API. This includes the
9
- * TamboAI client, the component registry, and the current thread context.
10
+ * TamboAI client, the component registry, the current thread context, and interactable components.
10
11
  * @param props - The props for the TamboProvider
11
12
  * @param props.children - The children to wrap
12
13
  * @param props.tamboUrl - The URL of the Tambo API
@@ -26,12 +27,13 @@ export const TamboProvider = ({ children, tamboUrl, apiKey, userToken, component
26
27
  React.createElement(TamboRegistryProvider, { components: components, tools: tools },
27
28
  React.createElement(TamboThreadProvider, { streaming: streaming },
28
29
  React.createElement(TamboComponentProvider, null,
29
- React.createElement(TamboCompositeProvider, null, children))))));
30
+ React.createElement(TamboInteractableProvider, null,
31
+ React.createElement(TamboCompositeProvider, null, children)))))));
30
32
  };
31
33
  export const TamboContext = createContext({});
32
34
  /**
33
35
  * TamboCompositeProvider is a provider that combines the TamboClient,
34
- * TamboThread, and TamboComponent providers
36
+ * TamboThread, TamboComponent, and TamboInteractable providers
35
37
  * @param props - The props for the TamboCompositeProvider
36
38
  * @param props.children - The children to wrap
37
39
  * @returns The wrapped component
@@ -41,18 +43,21 @@ export const TamboCompositeProvider = ({ children, }) => {
41
43
  const client = useTamboClient();
42
44
  const queryClient = useTamboQueryClient();
43
45
  const componentRegistry = useTamboComponent();
46
+ const interactableComponents = useTamboInteractable();
44
47
  return (React.createElement(TamboContext.Provider, { value: {
45
48
  client,
46
49
  queryClient,
47
50
  ...componentRegistry,
48
51
  ...threads,
52
+ ...interactableComponents,
49
53
  } }, children));
50
54
  };
51
55
  /**
52
56
  * The useTambo hook provides access to the Tambo API. This is the primary entrypoint
53
57
  * for the Tambo React SDK.
54
58
  *
55
- * This includes the TamboAI client, the component registry, and the current thread context.
59
+ * This includes the TamboAI client, the component registry, the current thread context,
60
+ * and interactable component management.
56
61
  * @returns The Tambo API
57
62
  */
58
63
  export const useTambo = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,mBAAmB,EAEnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAMtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,GACV,EAAE,EAAE;IACH,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CACL,oBAAC,mBAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;QAEpB,oBAAC,qBAAqB,IAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK;YACzD,oBAAC,mBAAmB,IAAC,SAAS,EAAE,SAAS;gBACvC,oBAAC,sBAAsB;oBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;IAE9C,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider components={components} tools={tools}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
1
+ {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,mBAAmB,EAEnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAMtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,GACV,EAAE,EAAE;IACH,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CACL,oBAAC,mBAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;QAEpB,oBAAC,qBAAqB,IAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK;YACzD,oBAAC,mBAAmB,IAAC,SAAS,EAAE,SAAS;gBACvC,oBAAC,sBAAsB;oBACrB,oBAAC,yBAAyB;wBACxB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACjC,CACL,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAOF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,oBAAoB,EAAE,CAAC;IAEtD,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;SAC1B,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider components={components} tools={tools}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps &\n TamboInteractableContext;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AACA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,yDAAyD,CAAC;AACjF,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,eAAe,EAEf,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAYpD,MAAM,WAAW,uBAAuB;IACtC,yBAAyB;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,mCAAmC;IACnC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACjE,yBAAyB;IACzB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,6BAA6B;IAC7B,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D,gFAAgF;IAChF,kBAAkB,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,0CAA0C;IAC1C,gBAAgB,EAAE,CAChB,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACnD,6CAA6C;IAC7C,mBAAmB,EAAE,CACnB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,sBAAsB;IACtB,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,2CAA2C;IAC3C,iBAAiB,EAAE,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjC,oFAAoF;IACpF,eAAe,EAAE,eAAe,CAAC;IACjC,6FAA6F;IAC7F,uBAAuB,EAAE,MAAM,CAAC;IAChC,iCAAiC;IACjC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAOhC,CAAC;AAEF,eAAO,MAAM,kBAAkB,wCA0D7B,CAAC;AAEH,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CACxC,iBAAiB,CAAC,wBAAwB,CAAC,CA+rB5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC"}
1
+ {"version":3,"file":"tambo-thread-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AACA,OAAO,OAA0B,MAAM,0B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AAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,2CAA2C;IAC3C,iBAAiB,EAAE,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjC,oFAAoF;IACpF,eAAe,EAAE,eAAe,CAAC;IACjC,6FAA6F;IAC7F,uBAAuB,EAAE,MAAM,CAAC;IAChC,iCAAiC;IACjC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAOhC,CAAC;AAEF,eAAO,MAAM,kBAAkB,wCA0D7B,CAAC;AAEH,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CACxC,iBAAiB,CAAC,wBAAwB,CAAC,CAktB5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC"}
@@ -361,6 +361,12 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
361
361
  updateThreadStatus(threadId, GenerationStage.STREAMING_RESPONSE);
362
362
  for await (const chunk of stream) {
363
363
  if (chunk.responseMessageDto.toolCallRequest) {
364
+ // Increment tool call count for this tool
365
+ const toolName = chunk.responseMessageDto.toolCallRequest.toolName;
366
+ if (toolName && params.toolCallCounts) {
367
+ params.toolCallCounts[toolName] =
368
+ (params.toolCallCounts[toolName] ?? 0) + 1;
369
+ }
364
370
  updateThreadStatus(chunk.responseMessageDto.threadId, GenerationStage.FETCHING_CONTEXT);
365
371
  updateThreadMessage(chunk.responseMessageDto.id, {
366
372
  ...chunk.responseMessageDto,
@@ -486,6 +492,8 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
486
492
  }, false);
487
493
  const availableComponents = getAvailableComponents(componentList, toolRegistry, componentToolAssociations);
488
494
  const unassociatedTools = getUnassociatedTools(toolRegistry, componentToolAssociations);
495
+ // Track tool call counts for this message processing
496
+ const toolCallCounts = {};
489
497
  const params = {
490
498
  messageToAppend: {
491
499
  content: [{ type: "text", text: message }],
@@ -495,6 +503,7 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
495
503
  availableComponents: availableComponents,
496
504
  clientTools: unassociatedTools.map((tool) => mapTamboToolToContextTool(tool)),
497
505
  forceToolChoice: forceToolChoice,
506
+ toolCallCounts,
498
507
  };
499
508
  if (streamResponse) {
500
509
  const advanceStreamResponse = await advanceStream(client, params, threadId === PLACEHOLDER_THREAD.id ? undefined : threadId);
@@ -505,6 +514,11 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
505
514
  : client.beta.threads.advanceById(threadId, params));
506
515
  //handle tool calls
507
516
  while (advanceResponse.responseMessageDto.toolCallRequest) {
517
+ // Increment tool call count for this tool
518
+ const toolName = advanceResponse.responseMessageDto.toolCallRequest.toolName;
519
+ if (toolName) {
520
+ toolCallCounts[toolName] = (toolCallCounts[toolName] || 0) + 1;
521
+ }
508
522
  updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);
509
523
  const toolCallResponse = await handleToolCall(advanceResponse.responseMessageDto, toolRegistry);
510
524
  const toolResponseString = typeof toolCallResponse.result === "string"
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;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SAAS;YACT,eAAe,EAAE,CAAC,aAAa,EAAE,eAAe;gBAC9C,eAAe,CAAC,IAAI,CAAoB;YAC1C,uBAAuB,EAAE,aAAa,EAAE,aAAa,IAAI,EAAE;YAC3D,MAAM;YACN,MAAM;SACP,IAEA,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI, { advanceStream } from \"@tambo-ai/typescript-sdk\";\nimport { Thread } from \"@tambo-ai/typescript-sdk/resources/beta/threads/threads\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n GenerationStage,\n isIdleStage,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { renderComponentIntoMessage } from \"../util/generate-component\";\nimport {\n getAvailableComponents,\n getClientContext,\n getUnassociatedTools,\n mapTamboToolToContextTool,\n} from \"../util/registry\";\nimport { handleToolCall } from \"../util/tool-caller\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\nexport interface TamboThreadContextProps {\n /** The current thread */\n thread: TamboThread;\n /** Switch to a different thread */\n switchCurrentThread: (threadId: string, fetch?: boolean) => void;\n /** Start a new thread */\n startNewThread: () => void;\n /** Update a thread's name */\n updateThreadName: (name: string, threadId?: string) => void;\n /** Let Tambo generate and set a thread's name based on the thread's messages */\n generateThreadName: (threadId?: string) => Promise<Thread>;\n /** Add a message to the current thread */\n addThreadMessage: (\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;\n /** Update a message in the current thread */\n updateThreadMessage: (\n id: string,\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<void>;\n /** Cancel a thread */\n cancel: (threadId?: string) => Promise<void>;\n /** The input value of the current thread */\n inputValue: string;\n /** Whether the thread is streaming */\n streaming: boolean;\n /** Set the input value of the current thread */\n setInputValue: (value: string) => void;\n /** Send a message to the current thread */\n sendThreadMessage: (\n message: string,\n options?: {\n threadId?: string;\n streamResponse?: boolean;\n contextKey?: string;\n forceToolChoice?: string;\n },\n ) => Promise<TamboThreadMessage>;\n /** The generation stage of the current thread - updated as the thread progresses */\n generationStage: GenerationStage;\n /** The generation status message of the current thread - updated as the thread progresses */\n generationStatusMessage: string;\n /** Whether the thread is idle */\n isIdle: boolean;\n}\n\n/**\n * This is a stub entry for when the thread is not yet created, the first time\n * the user sends a message\n *\n * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,\n * as this doesn't really exist on the server side.\n */\nexport const PLACEHOLDER_THREAD: TamboThread = {\n id: \"placeholder\",\n messages: [],\n createdAt: \"\",\n projectId: \"\",\n updatedAt: \"\",\n metadata: {},\n};\n\nexport const TamboThreadContext = createContext<TamboThreadContextProps>({\n thread: PLACEHOLDER_THREAD,\n /**\n *\n */\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented\");\n },\n /**\n *\n */\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented\");\n },\n /**\n *\n */\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented\");\n },\n /**\n *\n */\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented\");\n },\n /**\n *\n */\n addThreadMessage: () => {\n throw new Error(\"updateThreadMessageHistory not implemented\");\n },\n inputValue: \"\",\n streaming: true,\n /**\n *\n */\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented\");\n },\n /**\n *\n */\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n /**\n *\n */\n sendThreadMessage: () => {\n throw new Error(\"advance not implemented\");\n },\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n cancel: () => {\n throw new Error(\"cancel not implemented\");\n },\n});\n\nexport interface TamboThreadProviderProps {\n /** Whether to stream the response */\n streaming?: boolean;\n}\n\n/**\n * The TamboThreadProvider is a React provider that provides a thread context\n * to the descendants of the provider.\n * @param props - The props for the TamboThreadProvider\n * @param props.children - The children to wrap\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboThreadProvider component\n */\nexport const TamboThreadProvider: React.FC<\n PropsWithChildren<TamboThreadProviderProps>\n> = ({ children, streaming = true }) => {\n const [threadMap, setThreadMap] = useState<Record<string, TamboThread>>({\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n });\n const client = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n const [inputValue, setInputValue] = useState(\"\");\n const [ignoreResponse, setIgnoreResponse] = useState(false);\n const ignoreResponseRef = useRef(ignoreResponse);\n const [currentThreadId, setCurrentThreadId] = useState<string>(\n PLACEHOLDER_THREAD.id,\n );\n const currentThread: TamboThread | undefined = threadMap[currentThreadId];\n\n // Use existing messages from the current thread to avoid re-generating any components\n const currentMessageCache = useMemo(() => {\n const messageCache = new Map<string, TamboThreadMessage>();\n if (currentThread) {\n for (const message of currentThread.messages) {\n messageCache.set(message.id, message);\n }\n }\n return messageCache;\n }, [currentThread]);\n\n useEffect(() => {\n ignoreResponseRef.current = ignoreResponse;\n }, [ignoreResponse]);\n\n const isIdle = useMemo(\n () =>\n isIdleStage(\n (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n ),\n [currentThread?.generationStage],\n );\n\n const fetchThread = useCallback(\n async (threadId: string, includeInternalMessages = true) => {\n const thread = await client.beta.threads.retrieve(threadId, {\n includeInternal: includeInternalMessages,\n });\n const threadWithRenderedComponents = {\n ...thread,\n messages: thread.messages.map((message) => {\n if (currentMessageCache.has(message.id)) {\n const renderedMessage = currentMessageCache.get(message.id);\n return {\n ...renderedMessage,\n ...message,\n };\n }\n if (message.component?.componentName) {\n const messageWithComponent = renderComponentIntoMessage(\n message,\n componentList,\n );\n return messageWithComponent;\n }\n return message;\n }),\n };\n\n setThreadMap((prevMap) => {\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: threadWithRenderedComponents,\n };\n return updatedThreadMap;\n });\n },\n [client.beta.threads, componentList, currentMessageCache],\n );\n\n useEffect(() => {\n if (\n currentThreadId &&\n currentThreadId !== PLACEHOLDER_THREAD.id &&\n !threadMap[currentThreadId]\n ) {\n fetchThread(currentThreadId);\n }\n }, [currentThreadId, fetchThread, threadMap]);\n\n const addThreadMessage = useCallback(\n async (\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n if (!currentThread) {\n console.warn(\"Cannot add messages if we do not have a current thread\");\n return [];\n }\n const chatMessage: TamboThreadMessage & {\n additionalContext?: string;\n } = {\n ...message,\n additionalContext:\n message.role === \"user\" ? getClientContext() : undefined,\n createdAt,\n };\n const threadId = message.threadId;\n const messageId = chatMessage.id;\n // optimistically update the thread in the local state\n setThreadMap((prevMap) => {\n if (!threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[threadId]?.messages || [];\n const haveMessage = prevMessages.find((msg) => msg.id === messageId);\n // Update in place if the message already exists\n const updatedMessages = haveMessage\n ? prevMessages.map((msg) => {\n if (msg.id === messageId) {\n return chatMessage;\n }\n return msg;\n })\n : [...prevMessages, chatMessage];\n\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n messages: updatedMessages,\n },\n };\n return updatedThreadMap;\n });\n\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(message.threadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n return threadMap[threadId]?.messages || [];\n },\n [client.beta.threads.messages, currentThread, threadMap],\n );\n\n const updateThreadMessage = useCallback(\n async (\n id: string,\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n const chatMessage: TamboThreadMessage = {\n ...message,\n createdAt,\n };\n\n setThreadMap((prevMap) => {\n if (!message.threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n return chatMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(message.threadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n },\n [client.beta.threads.messages],\n );\n\n const startNewThread = useCallback(() => {\n setCurrentThreadId(PLACEHOLDER_THREAD.id);\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n };\n });\n }, []);\n\n const updateThreadName = useCallback(\n async (name: string, threadId?: string) => {\n threadId ??= currentThreadId;\n\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n return { ...prevMap, [threadId]: { ...prevMap[threadId], name } };\n });\n\n if (threadId !== PLACEHOLDER_THREAD.id) {\n const currentProject = await client.beta.projects.getCurrent();\n await client.beta.threads.update(threadId, {\n name,\n projectId: currentProject.id,\n });\n }\n },\n [currentThreadId, client.beta.projects, client.beta.threads],\n );\n\n const generateThreadName = useCallback(\n async (threadId?: string) => {\n threadId ??= currentThreadId;\n if (threadId === PLACEHOLDER_THREAD.id) {\n console.warn(\"Cannot generate name for empty thread\");\n return threadMap[threadId];\n }\n\n const threadWithGeneratedName =\n await client.beta.threads.generateName(threadId);\n\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n name: threadWithGeneratedName.name,\n },\n };\n });\n return threadWithGeneratedName;\n },\n [client.beta.threads, currentThreadId, threadMap],\n );\n\n const switchCurrentThread = useCallback(\n async (threadId: string, fetch = true) => {\n if (threadId === PLACEHOLDER_THREAD.id) {\n console.warn(\"Switching to placeholder thread, may be a bug.\");\n return;\n }\n setCurrentThreadId(threadId);\n setThreadMap((prevMap) => {\n if (prevMap[threadId]) {\n return prevMap;\n }\n // If this is a new thread, add placeholder thread messages to the thread\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[PLACEHOLDER_THREAD.id],\n id: threadId,\n },\n };\n return updatedThreadMap;\n });\n if (fetch) {\n await fetchThread(threadId);\n }\n },\n [fetchThread],\n );\n\n const updateThreadStatus = useCallback(\n (threadId: string, stage: GenerationStage, statusMessage?: string) => {\n setThreadMap((prevMap) => {\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n generationStage: stage,\n statusMessage: statusMessage,\n },\n };\n return updatedThreadMap;\n });\n },\n [],\n );\n\n const cancel = useCallback(\n async (threadId?: string) => {\n threadId ??= currentThreadId;\n if (isIdle) {\n return;\n }\n setIgnoreResponse(true);\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n generationStage: GenerationStage.CANCELLED,\n messages: prevMap[threadId].messages.map((message) => {\n if (\n message.id ===\n prevMap[threadId].messages[\n prevMap[threadId].messages.length - 1\n ].id\n ) {\n return {\n ...message,\n isCancelled: true,\n };\n }\n return message;\n }),\n },\n };\n });\n\n await client.beta.threads.cancel(threadId);\n },\n [client.beta.threads, currentThreadId, isIdle],\n );\n\n const handleAdvanceStream = useCallback(\n async (\n stream: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>,\n params: TamboAI.Beta.Threads.ThreadAdvanceParams,\n threadId: string,\n ): Promise<TamboThreadMessage> => {\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n return {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n };\n }\n let finalMessage: Readonly<TamboThreadMessage> | undefined;\n let hasSetThreadId = false;\n updateThreadStatus(threadId, GenerationStage.STREAMING_RESPONSE);\n\n for await (const chunk of stream) {\n if (chunk.responseMessageDto.toolCallRequest) {\n updateThreadStatus(\n chunk.responseMessageDto.threadId,\n GenerationStage.FETCHING_CONTEXT,\n );\n\n updateThreadMessage(\n chunk.responseMessageDto.id,\n {\n ...chunk.responseMessageDto,\n },\n false,\n );\n\n const toolCallResponse = await handleToolCall(\n chunk.responseMessageDto,\n toolRegistry,\n );\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n {\n return {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n };\n }\n }\n const toolCallResponseString =\n typeof toolCallResponse.result === \"string\"\n ? toolCallResponse.result\n : JSON.stringify(toolCallResponse.result);\n const toolCallResponseParams: TamboAI.Beta.Threads.ThreadAdvanceParams =\n {\n ...params,\n messageToAppend: {\n content: [{ type: \"text\", text: toolCallResponseString }],\n role: \"tool\",\n actionType: \"tool_response\",\n component: chunk.responseMessageDto.component,\n tool_call_id: chunk.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n };\n\n updateThreadMessage(\n chunk.responseMessageDto.id,\n {\n ...chunk.responseMessageDto,\n error: toolCallResponse.error,\n },\n false,\n );\n\n addThreadMessage(\n {\n threadId: chunk.responseMessageDto.threadId,\n content: [{ type: \"text\", text: toolCallResponseString }],\n role: \"tool\",\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n actionType: \"tool_response\",\n tool_call_id: chunk.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n false,\n );\n\n updateThreadStatus(\n chunk.responseMessageDto.threadId,\n GenerationStage.STREAMING_RESPONSE,\n );\n const toolCallResponseStream = await advanceStream(\n client,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n\n return await handleAdvanceStream(\n toolCallResponseStream,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n } else {\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n return (\n finalMessage ?? {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n }\n );\n }\n if (\n !hasSetThreadId &&\n chunk.responseMessageDto.threadId &&\n chunk.responseMessageDto.threadId !== currentThread?.id\n ) {\n hasSetThreadId = true;\n await switchCurrentThread(chunk.responseMessageDto.threadId, false);\n }\n\n if (!finalMessage) {\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n await addThreadMessage(finalMessage, false);\n } else {\n // if we start getting a new message mid-stream, put the previous one on screen\n const isNewMessage =\n chunk.responseMessageDto.id !== finalMessage.id;\n\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n\n if (isNewMessage) {\n await addThreadMessage(finalMessage, false);\n } else {\n await updateThreadMessage(finalMessage.id, finalMessage, false);\n }\n }\n }\n }\n\n updateThreadStatus(\n finalMessage?.threadId ?? threadId,\n GenerationStage.COMPLETE,\n );\n return (\n finalMessage ?? {\n threadId: \"\",\n content: [{ type: \"text\", text: `Error processing stream` }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n }\n );\n },\n [\n addThreadMessage,\n client,\n componentList,\n currentThread?.id,\n switchCurrentThread,\n toolRegistry,\n updateThreadMessage,\n updateThreadStatus,\n ],\n );\n\n const currentThreadContextKey = currentThread?.contextKey;\n\n const sendThreadMessage = useCallback(\n async (\n message: string,\n options: {\n threadId?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n contextKey?: string;\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? PLACEHOLDER_THREAD.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey = currentThreadContextKey,\n } = options;\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n\n addThreadMessage(\n {\n content: [{ type: \"text\", text: message }],\n renderedComponent: null,\n role: \"user\",\n threadId: threadId,\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n },\n false,\n );\n\n const availableComponents = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n const unassociatedTools = getUnassociatedTools(\n toolRegistry,\n componentToolAssociations,\n );\n const params: TamboAI.Beta.Threads.ThreadAdvanceParams = {\n messageToAppend: {\n content: [{ type: \"text\", text: message }],\n role: \"user\",\n },\n contextKey,\n availableComponents: availableComponents,\n clientTools: unassociatedTools.map((tool) =>\n mapTamboToolToContextTool(tool),\n ),\n forceToolChoice: forceToolChoice,\n };\n\n if (streamResponse) {\n const advanceStreamResponse = await advanceStream(\n client,\n params,\n threadId === PLACEHOLDER_THREAD.id ? undefined : threadId,\n );\n return await handleAdvanceStream(\n advanceStreamResponse,\n params,\n threadId,\n );\n }\n let advanceResponse = await (threadId === PLACEHOLDER_THREAD.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceById(threadId, params));\n\n //handle tool calls\n while (advanceResponse.responseMessageDto.toolCallRequest) {\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n advanceResponse.responseMessageDto,\n toolRegistry,\n );\n const toolResponseString =\n typeof toolCallResponse.result === \"string\"\n ? toolCallResponse.result\n : JSON.stringify(toolCallResponse.result);\n const toolCallResponseParams: TamboAI.Beta.Threads.ThreadAdvanceParams =\n {\n ...params,\n messageToAppend: {\n ...params.messageToAppend,\n content: [{ type: \"text\", text: toolResponseString }],\n role: \"tool\",\n actionType: \"tool_response\",\n component: advanceResponse.responseMessageDto.component,\n tool_call_id: advanceResponse.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n };\n if (toolCallResponse.error) {\n //update toolcall message with error\n const toolCallMessage = {\n ...advanceResponse.responseMessageDto,\n error: toolCallResponse.error,\n };\n updateThreadMessage(toolCallMessage.id, toolCallMessage, false);\n }\n updateThreadStatus(threadId, GenerationStage.HYDRATING_COMPONENT);\n addThreadMessage(\n {\n threadId: threadId,\n content: [{ type: \"text\", text: toolResponseString }],\n role: \"tool\",\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n actionType: \"tool_response\",\n tool_call_id: advanceResponse.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n false,\n );\n\n advanceResponse = await client.beta.threads.advanceById(\n advanceResponse.responseMessageDto.threadId,\n toolCallResponseParams,\n );\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.COMPLETE,\n );\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThreadId,\n currentThreadContextKey,\n switchCurrentThread,\n addThreadMessage,\n client,\n updateThreadMessage,\n updateThreadStatus,\n handleAdvanceStream,\n streaming,\n ],\n );\n\n return (\n <TamboThreadContext.Provider\n value={{\n thread: currentThread,\n switchCurrentThread,\n startNewThread,\n updateThreadName,\n generateThreadName,\n addThreadMessage,\n updateThreadMessage,\n inputValue,\n setInputValue,\n sendThreadMessage,\n streaming,\n generationStage: (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n generationStatusMessage: currentThread?.statusMessage ?? \"\",\n isIdle,\n cancel,\n }}\n >\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * The useTamboThread hook provides access to the current thread context\n * to the descendants of the TamboThreadProvider.\n * @returns All state and actions for the current thread\n */\nexport const useTamboThread = () => {\n const context = useContext(TamboThreadContext);\n if (context === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n return context;\n};\n"]}
1
+ {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EACL,eAAe,EACf,WAAW,GAEZ,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAkD7D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC7C,EAAE,EAAE,aAAa;IACjB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAA0B;IACvE,MAAM,EAAE,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BAC9C,eAAe,CAAC,IAAI,CAAoB;YAC1C,uBAAuB,EAAE,aAAa,EAAE,aAAa,IAAI,EAAE;YAC3D,MAAM;YACN,MAAM;SACP,IAEA,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI, { advanceStream } from \"@tambo-ai/typescript-sdk\";\nimport { Thread } from \"@tambo-ai/typescript-sdk/resources/beta/threads/threads\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n GenerationStage,\n isIdleStage,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { renderComponentIntoMessage } from \"../util/generate-component\";\nimport {\n getAvailableComponents,\n getClientContext,\n getUnassociatedTools,\n mapTamboToolToContextTool,\n} from \"../util/registry\";\nimport { handleToolCall } from \"../util/tool-caller\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\nexport interface TamboThreadContextProps {\n /** The current thread */\n thread: TamboThread;\n /** Switch to a different thread */\n switchCurrentThread: (threadId: string, fetch?: boolean) => void;\n /** Start a new thread */\n startNewThread: () => void;\n /** Update a thread's name */\n updateThreadName: (name: string, threadId?: string) => void;\n /** Let Tambo generate and set a thread's name based on the thread's messages */\n generateThreadName: (threadId?: string) => Promise<Thread>;\n /** Add a message to the current thread */\n addThreadMessage: (\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;\n /** Update a message in the current thread */\n updateThreadMessage: (\n id: string,\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<void>;\n /** Cancel a thread */\n cancel: (threadId?: string) => Promise<void>;\n /** The input value of the current thread */\n inputValue: string;\n /** Whether the thread is streaming */\n streaming: boolean;\n /** Set the input value of the current thread */\n setInputValue: (value: string) => void;\n /** Send a message to the current thread */\n sendThreadMessage: (\n message: string,\n options?: {\n threadId?: string;\n streamResponse?: boolean;\n contextKey?: string;\n forceToolChoice?: string;\n },\n ) => Promise<TamboThreadMessage>;\n /** The generation stage of the current thread - updated as the thread progresses */\n generationStage: GenerationStage;\n /** The generation status message of the current thread - updated as the thread progresses */\n generationStatusMessage: string;\n /** Whether the thread is idle */\n isIdle: boolean;\n}\n\n/**\n * This is a stub entry for when the thread is not yet created, the first time\n * the user sends a message\n *\n * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,\n * as this doesn't really exist on the server side.\n */\nexport const PLACEHOLDER_THREAD: TamboThread = {\n id: \"placeholder\",\n messages: [],\n createdAt: \"\",\n projectId: \"\",\n updatedAt: \"\",\n metadata: {},\n};\n\nexport const TamboThreadContext = createContext<TamboThreadContextProps>({\n thread: PLACEHOLDER_THREAD,\n /**\n *\n */\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented\");\n },\n /**\n *\n */\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented\");\n },\n /**\n *\n */\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented\");\n },\n /**\n *\n */\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented\");\n },\n /**\n *\n */\n addThreadMessage: () => {\n throw new Error(\"updateThreadMessageHistory not implemented\");\n },\n inputValue: \"\",\n streaming: true,\n /**\n *\n */\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented\");\n },\n /**\n *\n */\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n /**\n *\n */\n sendThreadMessage: () => {\n throw new Error(\"advance not implemented\");\n },\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n cancel: () => {\n throw new Error(\"cancel not implemented\");\n },\n});\n\nexport interface TamboThreadProviderProps {\n /** Whether to stream the response */\n streaming?: boolean;\n}\n\n/**\n * The TamboThreadProvider is a React provider that provides a thread context\n * to the descendants of the provider.\n * @param props - The props for the TamboThreadProvider\n * @param props.children - The children to wrap\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboThreadProvider component\n */\nexport const TamboThreadProvider: React.FC<\n PropsWithChildren<TamboThreadProviderProps>\n> = ({ children, streaming = true }) => {\n const [threadMap, setThreadMap] = useState<Record<string, TamboThread>>({\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n });\n const client = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n const [inputValue, setInputValue] = useState(\"\");\n const [ignoreResponse, setIgnoreResponse] = useState(false);\n const ignoreResponseRef = useRef(ignoreResponse);\n const [currentThreadId, setCurrentThreadId] = useState<string>(\n PLACEHOLDER_THREAD.id,\n );\n const currentThread: TamboThread | undefined = threadMap[currentThreadId];\n\n // Use existing messages from the current thread to avoid re-generating any components\n const currentMessageCache = useMemo(() => {\n const messageCache = new Map<string, TamboThreadMessage>();\n if (currentThread) {\n for (const message of currentThread.messages) {\n messageCache.set(message.id, message);\n }\n }\n return messageCache;\n }, [currentThread]);\n\n useEffect(() => {\n ignoreResponseRef.current = ignoreResponse;\n }, [ignoreResponse]);\n\n const isIdle = useMemo(\n () =>\n isIdleStage(\n (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n ),\n [currentThread?.generationStage],\n );\n\n const fetchThread = useCallback(\n async (threadId: string, includeInternalMessages = true) => {\n const thread = await client.beta.threads.retrieve(threadId, {\n includeInternal: includeInternalMessages,\n });\n const threadWithRenderedComponents = {\n ...thread,\n messages: thread.messages.map((message) => {\n if (currentMessageCache.has(message.id)) {\n const renderedMessage = currentMessageCache.get(message.id);\n return {\n ...renderedMessage,\n ...message,\n };\n }\n if (message.component?.componentName) {\n const messageWithComponent = renderComponentIntoMessage(\n message,\n componentList,\n );\n return messageWithComponent;\n }\n return message;\n }),\n };\n\n setThreadMap((prevMap) => {\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: threadWithRenderedComponents,\n };\n return updatedThreadMap;\n });\n },\n [client.beta.threads, componentList, currentMessageCache],\n );\n\n useEffect(() => {\n if (\n currentThreadId &&\n currentThreadId !== PLACEHOLDER_THREAD.id &&\n !threadMap[currentThreadId]\n ) {\n fetchThread(currentThreadId);\n }\n }, [currentThreadId, fetchThread, threadMap]);\n\n const addThreadMessage = useCallback(\n async (\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n if (!currentThread) {\n console.warn(\"Cannot add messages if we do not have a current thread\");\n return [];\n }\n const chatMessage: TamboThreadMessage & {\n additionalContext?: string;\n } = {\n ...message,\n additionalContext:\n message.role === \"user\" ? getClientContext() : undefined,\n createdAt,\n };\n const threadId = message.threadId;\n const messageId = chatMessage.id;\n // optimistically update the thread in the local state\n setThreadMap((prevMap) => {\n if (!threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[threadId]?.messages || [];\n const haveMessage = prevMessages.find((msg) => msg.id === messageId);\n // Update in place if the message already exists\n const updatedMessages = haveMessage\n ? prevMessages.map((msg) => {\n if (msg.id === messageId) {\n return chatMessage;\n }\n return msg;\n })\n : [...prevMessages, chatMessage];\n\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n messages: updatedMessages,\n },\n };\n return updatedThreadMap;\n });\n\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(message.threadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n return threadMap[threadId]?.messages || [];\n },\n [client.beta.threads.messages, currentThread, threadMap],\n );\n\n const updateThreadMessage = useCallback(\n async (\n id: string,\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n const chatMessage: TamboThreadMessage = {\n ...message,\n createdAt,\n };\n\n setThreadMap((prevMap) => {\n if (!message.threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n return chatMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(message.threadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n },\n [client.beta.threads.messages],\n );\n\n const startNewThread = useCallback(() => {\n setCurrentThreadId(PLACEHOLDER_THREAD.id);\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n };\n });\n }, []);\n\n const updateThreadName = useCallback(\n async (name: string, threadId?: string) => {\n threadId ??= currentThreadId;\n\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n return { ...prevMap, [threadId]: { ...prevMap[threadId], name } };\n });\n\n if (threadId !== PLACEHOLDER_THREAD.id) {\n const currentProject = await client.beta.projects.getCurrent();\n await client.beta.threads.update(threadId, {\n name,\n projectId: currentProject.id,\n });\n }\n },\n [currentThreadId, client.beta.projects, client.beta.threads],\n );\n\n const generateThreadName = useCallback(\n async (threadId?: string) => {\n threadId ??= currentThreadId;\n if (threadId === PLACEHOLDER_THREAD.id) {\n console.warn(\"Cannot generate name for empty thread\");\n return threadMap[threadId];\n }\n\n const threadWithGeneratedName =\n await client.beta.threads.generateName(threadId);\n\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n name: threadWithGeneratedName.name,\n },\n };\n });\n return threadWithGeneratedName;\n },\n [client.beta.threads, currentThreadId, threadMap],\n );\n\n const switchCurrentThread = useCallback(\n async (threadId: string, fetch = true) => {\n if (threadId === PLACEHOLDER_THREAD.id) {\n console.warn(\"Switching to placeholder thread, may be a bug.\");\n return;\n }\n setCurrentThreadId(threadId);\n setThreadMap((prevMap) => {\n if (prevMap[threadId]) {\n return prevMap;\n }\n // If this is a new thread, add placeholder thread messages to the thread\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[PLACEHOLDER_THREAD.id],\n id: threadId,\n },\n };\n return updatedThreadMap;\n });\n if (fetch) {\n await fetchThread(threadId);\n }\n },\n [fetchThread],\n );\n\n const updateThreadStatus = useCallback(\n (threadId: string, stage: GenerationStage, statusMessage?: string) => {\n setThreadMap((prevMap) => {\n const updatedThreadMap = {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n generationStage: stage,\n statusMessage: statusMessage,\n },\n };\n return updatedThreadMap;\n });\n },\n [],\n );\n\n const cancel = useCallback(\n async (threadId?: string) => {\n threadId ??= currentThreadId;\n if (isIdle) {\n return;\n }\n setIgnoreResponse(true);\n setThreadMap((prevMap) => {\n if (!prevMap[threadId]) {\n return prevMap;\n }\n\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n generationStage: GenerationStage.CANCELLED,\n messages: prevMap[threadId].messages.map((message) => {\n if (\n message.id ===\n prevMap[threadId].messages[\n prevMap[threadId].messages.length - 1\n ].id\n ) {\n return {\n ...message,\n isCancelled: true,\n };\n }\n return message;\n }),\n },\n };\n });\n\n await client.beta.threads.cancel(threadId);\n },\n [client.beta.threads, currentThreadId, isIdle],\n );\n\n const handleAdvanceStream = useCallback(\n async (\n stream: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>,\n params: TamboAI.Beta.Threads.ThreadAdvanceParams,\n threadId: string,\n ): Promise<TamboThreadMessage> => {\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n return {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n };\n }\n let finalMessage: Readonly<TamboThreadMessage> | undefined;\n let hasSetThreadId = false;\n updateThreadStatus(threadId, GenerationStage.STREAMING_RESPONSE);\n\n for await (const chunk of stream) {\n if (chunk.responseMessageDto.toolCallRequest) {\n // Increment tool call count for this tool\n const toolName = chunk.responseMessageDto.toolCallRequest.toolName;\n if (toolName && params.toolCallCounts) {\n params.toolCallCounts[toolName] =\n (params.toolCallCounts[toolName] ?? 0) + 1;\n }\n\n updateThreadStatus(\n chunk.responseMessageDto.threadId,\n GenerationStage.FETCHING_CONTEXT,\n );\n\n updateThreadMessage(\n chunk.responseMessageDto.id,\n {\n ...chunk.responseMessageDto,\n },\n false,\n );\n\n const toolCallResponse = await handleToolCall(\n chunk.responseMessageDto,\n toolRegistry,\n );\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n {\n return {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n };\n }\n }\n const toolCallResponseString =\n typeof toolCallResponse.result === \"string\"\n ? toolCallResponse.result\n : JSON.stringify(toolCallResponse.result);\n const toolCallResponseParams: TamboAI.Beta.Threads.ThreadAdvanceParams =\n {\n ...params,\n messageToAppend: {\n content: [{ type: \"text\", text: toolCallResponseString }],\n role: \"tool\",\n actionType: \"tool_response\",\n component: chunk.responseMessageDto.component,\n tool_call_id: chunk.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n };\n\n updateThreadMessage(\n chunk.responseMessageDto.id,\n {\n ...chunk.responseMessageDto,\n error: toolCallResponse.error,\n },\n false,\n );\n\n addThreadMessage(\n {\n threadId: chunk.responseMessageDto.threadId,\n content: [{ type: \"text\", text: toolCallResponseString }],\n role: \"tool\",\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n actionType: \"tool_response\",\n tool_call_id: chunk.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n false,\n );\n\n updateThreadStatus(\n chunk.responseMessageDto.threadId,\n GenerationStage.STREAMING_RESPONSE,\n );\n const toolCallResponseStream = await advanceStream(\n client,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n\n return await handleAdvanceStream(\n toolCallResponseStream,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n } else {\n if (ignoreResponseRef.current) {\n setIgnoreResponse(false);\n return (\n finalMessage ?? {\n threadId: threadId,\n content: [{ type: \"text\", text: \"\" }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n }\n );\n }\n if (\n !hasSetThreadId &&\n chunk.responseMessageDto.threadId &&\n chunk.responseMessageDto.threadId !== currentThread?.id\n ) {\n hasSetThreadId = true;\n await switchCurrentThread(chunk.responseMessageDto.threadId, false);\n }\n\n if (!finalMessage) {\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n await addThreadMessage(finalMessage, false);\n } else {\n // if we start getting a new message mid-stream, put the previous one on screen\n const isNewMessage =\n chunk.responseMessageDto.id !== finalMessage.id;\n\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n\n if (isNewMessage) {\n await addThreadMessage(finalMessage, false);\n } else {\n await updateThreadMessage(finalMessage.id, finalMessage, false);\n }\n }\n }\n }\n\n updateThreadStatus(\n finalMessage?.threadId ?? threadId,\n GenerationStage.COMPLETE,\n );\n return (\n finalMessage ?? {\n threadId: \"\",\n content: [{ type: \"text\", text: `Error processing stream` }],\n role: \"assistant\",\n createdAt: new Date().toISOString(),\n id: crypto.randomUUID(),\n componentState: {},\n }\n );\n },\n [\n addThreadMessage,\n client,\n componentList,\n currentThread?.id,\n switchCurrentThread,\n toolRegistry,\n updateThreadMessage,\n updateThreadStatus,\n ],\n );\n\n const currentThreadContextKey = currentThread?.contextKey;\n\n const sendThreadMessage = useCallback(\n async (\n message: string,\n options: {\n threadId?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n contextKey?: string;\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? PLACEHOLDER_THREAD.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey = currentThreadContextKey,\n } = options;\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n\n addThreadMessage(\n {\n content: [{ type: \"text\", text: message }],\n renderedComponent: null,\n role: \"user\",\n threadId: threadId,\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n },\n false,\n );\n\n const availableComponents = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n const unassociatedTools = getUnassociatedTools(\n toolRegistry,\n componentToolAssociations,\n );\n\n // Track tool call counts for this message processing\n const toolCallCounts: Record<string, number> = {};\n\n const params: TamboAI.Beta.Threads.ThreadAdvanceParams = {\n messageToAppend: {\n content: [{ type: \"text\", text: message }],\n role: \"user\",\n },\n contextKey,\n availableComponents: availableComponents,\n clientTools: unassociatedTools.map((tool) =>\n mapTamboToolToContextTool(tool),\n ),\n forceToolChoice: forceToolChoice,\n toolCallCounts,\n };\n\n if (streamResponse) {\n const advanceStreamResponse = await advanceStream(\n client,\n params,\n threadId === PLACEHOLDER_THREAD.id ? undefined : threadId,\n );\n return await handleAdvanceStream(\n advanceStreamResponse,\n params,\n threadId,\n );\n }\n let advanceResponse = await (threadId === PLACEHOLDER_THREAD.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceById(threadId, params));\n\n //handle tool calls\n while (advanceResponse.responseMessageDto.toolCallRequest) {\n // Increment tool call count for this tool\n const toolName =\n advanceResponse.responseMessageDto.toolCallRequest.toolName;\n if (toolName) {\n toolCallCounts[toolName] = (toolCallCounts[toolName] || 0) + 1;\n }\n\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n advanceResponse.responseMessageDto,\n toolRegistry,\n );\n const toolResponseString =\n typeof toolCallResponse.result === \"string\"\n ? toolCallResponse.result\n : JSON.stringify(toolCallResponse.result);\n const toolCallResponseParams: TamboAI.Beta.Threads.ThreadAdvanceParams =\n {\n ...params,\n messageToAppend: {\n ...params.messageToAppend,\n content: [{ type: \"text\", text: toolResponseString }],\n role: \"tool\",\n actionType: \"tool_response\",\n component: advanceResponse.responseMessageDto.component,\n tool_call_id: advanceResponse.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n };\n if (toolCallResponse.error) {\n //update toolcall message with error\n const toolCallMessage = {\n ...advanceResponse.responseMessageDto,\n error: toolCallResponse.error,\n };\n updateThreadMessage(toolCallMessage.id, toolCallMessage, false);\n }\n updateThreadStatus(threadId, GenerationStage.HYDRATING_COMPONENT);\n addThreadMessage(\n {\n threadId: threadId,\n content: [{ type: \"text\", text: toolResponseString }],\n role: \"tool\",\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n actionType: \"tool_response\",\n tool_call_id: advanceResponse.responseMessageDto.tool_call_id,\n error: toolCallResponse.error,\n },\n false,\n );\n\n advanceResponse = await client.beta.threads.advanceById(\n advanceResponse.responseMessageDto.threadId,\n toolCallResponseParams,\n );\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.COMPLETE,\n );\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThreadId,\n currentThreadContextKey,\n switchCurrentThread,\n addThreadMessage,\n client,\n updateThreadMessage,\n updateThreadStatus,\n handleAdvanceStream,\n streaming,\n ],\n );\n\n return (\n <TamboThreadContext.Provider\n value={{\n thread: currentThread,\n switchCurrentThread,\n startNewThread,\n updateThreadName,\n generateThreadName,\n addThreadMessage,\n updateThreadMessage,\n inputValue,\n setInputValue,\n sendThreadMessage,\n streaming,\n generationStage: (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n generationStatusMessage: currentThread?.statusMessage ?? \"\",\n isIdle,\n cancel,\n }}\n >\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * The useTamboThread hook provides access to the current thread context\n * to the descendants of the TamboThreadProvider.\n * @returns All state and actions for the current thread\n */\nexport const useTamboThread = () => {\n const context = useContext(TamboThreadContext);\n if (context === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n return context;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.37.2",
3
+ "version": "0.38.0",
4
4
  "description": "React client package for Tambo AI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@modelcontextprotocol/sdk": "^1.15.0",
71
- "@tambo-ai/typescript-sdk": "^0.61.0",
71
+ "@tambo-ai/typescript-sdk": "^0.63.0",
72
72
  "@tanstack/react-query": "^5.81.5",
73
73
  "partial-json": "^0.1.7",
74
74
  "react-fast-compare": "^3.2.2",