@tambo-ai/react 0.41.2 → 0.42.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 (107) hide show
  1. package/dist/context-helpers/__tests__/context-helpers.test.d.ts +2 -0
  2. package/dist/context-helpers/__tests__/context-helpers.test.d.ts.map +1 -0
  3. package/dist/context-helpers/__tests__/context-helpers.test.js +44 -0
  4. package/dist/context-helpers/__tests__/context-helpers.test.js.map +1 -0
  5. package/dist/context-helpers/index.d.ts +9 -0
  6. package/dist/context-helpers/index.d.ts.map +1 -0
  7. package/dist/context-helpers/index.js +38 -0
  8. package/dist/context-helpers/index.js.map +1 -0
  9. package/dist/context-helpers/types.d.ts +30 -0
  10. package/dist/context-helpers/types.d.ts.map +1 -0
  11. package/dist/context-helpers/types.js +3 -0
  12. package/dist/context-helpers/types.js.map +1 -0
  13. package/dist/context-helpers/user-page.d.ts +7 -0
  14. package/dist/context-helpers/user-page.d.ts.map +1 -0
  15. package/dist/context-helpers/user-page.js +31 -0
  16. package/dist/context-helpers/user-page.js.map +1 -0
  17. package/dist/context-helpers/user-time.d.ts +7 -0
  18. package/dist/context-helpers/user-time.d.ts.map +1 -0
  19. package/dist/context-helpers/user-time.js +20 -0
  20. package/dist/context-helpers/user-time.js.map +1 -0
  21. package/dist/index.d.ts +3 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/providers/__tests__/tambo-context-helpers-provider.test.d.ts +2 -0
  26. package/dist/providers/__tests__/tambo-context-helpers-provider.test.d.ts.map +1 -0
  27. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +194 -0
  28. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -0
  29. package/dist/providers/__tests__/tambo-thread-provider.test.js +51 -31
  30. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  31. package/dist/providers/index.d.ts +1 -0
  32. package/dist/providers/index.d.ts.map +1 -1
  33. package/dist/providers/index.js +4 -1
  34. package/dist/providers/index.js.map +1 -1
  35. package/dist/providers/tambo-context-helpers-provider.d.ts +28 -0
  36. package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -0
  37. package/dist/providers/tambo-context-helpers-provider.js +98 -0
  38. package/dist/providers/tambo-context-helpers-provider.js.map +1 -0
  39. package/dist/providers/tambo-provider.d.ts +4 -2
  40. package/dist/providers/tambo-provider.d.ts.map +1 -1
  41. package/dist/providers/tambo-provider.js +10 -5
  42. package/dist/providers/tambo-provider.js.map +1 -1
  43. package/dist/providers/tambo-stubs.d.ts +4 -0
  44. package/dist/providers/tambo-stubs.d.ts.map +1 -1
  45. package/dist/providers/tambo-stubs.js +6 -3
  46. package/dist/providers/tambo-stubs.js.map +1 -1
  47. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  48. package/dist/providers/tambo-thread-provider.js +10 -1
  49. package/dist/providers/tambo-thread-provider.js.map +1 -1
  50. package/dist/util/registry.d.ts +0 -8
  51. package/dist/util/registry.d.ts.map +1 -1
  52. package/dist/util/registry.js +1 -15
  53. package/dist/util/registry.js.map +1 -1
  54. package/esm/context-helpers/__tests__/context-helpers.test.d.ts +2 -0
  55. package/esm/context-helpers/__tests__/context-helpers.test.d.ts.map +1 -0
  56. package/esm/context-helpers/__tests__/context-helpers.test.js +42 -0
  57. package/esm/context-helpers/__tests__/context-helpers.test.js.map +1 -0
  58. package/esm/context-helpers/index.d.ts +9 -0
  59. package/esm/context-helpers/index.d.ts.map +1 -0
  60. package/esm/context-helpers/index.js +21 -0
  61. package/esm/context-helpers/index.js.map +1 -0
  62. package/esm/context-helpers/types.d.ts +30 -0
  63. package/esm/context-helpers/types.d.ts.map +1 -0
  64. package/esm/context-helpers/types.js +2 -0
  65. package/esm/context-helpers/types.js.map +1 -0
  66. package/esm/context-helpers/user-page.d.ts +7 -0
  67. package/esm/context-helpers/user-page.d.ts.map +1 -0
  68. package/esm/context-helpers/user-page.js +28 -0
  69. package/esm/context-helpers/user-page.js.map +1 -0
  70. package/esm/context-helpers/user-time.d.ts +7 -0
  71. package/esm/context-helpers/user-time.d.ts.map +1 -0
  72. package/esm/context-helpers/user-time.js +17 -0
  73. package/esm/context-helpers/user-time.js.map +1 -0
  74. package/esm/index.d.ts +3 -1
  75. package/esm/index.d.ts.map +1 -1
  76. package/esm/index.js +3 -1
  77. package/esm/index.js.map +1 -1
  78. package/esm/providers/__tests__/tambo-context-helpers-provider.test.d.ts +2 -0
  79. package/esm/providers/__tests__/tambo-context-helpers-provider.test.d.ts.map +1 -0
  80. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +156 -0
  81. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -0
  82. package/esm/providers/__tests__/tambo-thread-provider.test.js +51 -31
  83. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  84. package/esm/providers/index.d.ts +1 -0
  85. package/esm/providers/index.d.ts.map +1 -1
  86. package/esm/providers/index.js +1 -0
  87. package/esm/providers/index.js.map +1 -1
  88. package/esm/providers/tambo-context-helpers-provider.d.ts +28 -0
  89. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -0
  90. package/esm/providers/tambo-context-helpers-provider.js +60 -0
  91. package/esm/providers/tambo-context-helpers-provider.js.map +1 -0
  92. package/esm/providers/tambo-provider.d.ts +4 -2
  93. package/esm/providers/tambo-provider.d.ts.map +1 -1
  94. package/esm/providers/tambo-provider.js +10 -5
  95. package/esm/providers/tambo-provider.js.map +1 -1
  96. package/esm/providers/tambo-stubs.d.ts +4 -0
  97. package/esm/providers/tambo-stubs.d.ts.map +1 -1
  98. package/esm/providers/tambo-stubs.js +6 -3
  99. package/esm/providers/tambo-stubs.js.map +1 -1
  100. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  101. package/esm/providers/tambo-thread-provider.js +11 -2
  102. package/esm/providers/tambo-thread-provider.js.map +1 -1
  103. package/esm/util/registry.d.ts +0 -8
  104. package/esm/util/registry.d.ts.map +1 -1
  105. package/esm/util/registry.js +0 -13
  106. package/esm/util/registry.js.map +1 -1
  107. package/package.json +1 -1
@@ -2,6 +2,7 @@
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 { TamboContextHelpersProvider, useTamboContextHelpers, } from "./tambo-context-helpers-provider";
5
6
  import { TamboInteractableProvider, useTamboInteractable, } from "./tambo-interactable-provider";
6
7
  import { TamboRegistryProvider, } from "./tambo-registry-provider";
7
8
  import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
@@ -16,19 +17,21 @@ import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
16
17
  * @param props.environment - The environment to use for the Tambo API
17
18
  * @param props.tools - The tools to register
18
19
  * @param props.streaming - Whether to stream the response by default. Defaults to true.
20
+ * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled
19
21
  * @returns The TamboProvider component
20
22
  */
21
- export const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, streaming, }) => {
23
+ export const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, streaming, contextHelpers, }) => {
22
24
  // Should only be used in browser
23
25
  if (typeof window === "undefined") {
24
26
  console.error("TamboProvider must be used within a browser");
25
27
  }
26
28
  return (React.createElement(TamboClientProvider, { tamboUrl: tamboUrl, apiKey: apiKey, environment: environment, userToken: userToken },
27
29
  React.createElement(TamboRegistryProvider, { components: components, tools: tools },
28
- React.createElement(TamboThreadProvider, { streaming: streaming },
29
- React.createElement(TamboComponentProvider, null,
30
- React.createElement(TamboInteractableProvider, null,
31
- React.createElement(TamboCompositeProvider, null, children)))))));
30
+ React.createElement(TamboContextHelpersProvider, { contextHelpers: contextHelpers },
31
+ React.createElement(TamboThreadProvider, { streaming: streaming },
32
+ React.createElement(TamboComponentProvider, null,
33
+ React.createElement(TamboInteractableProvider, null,
34
+ React.createElement(TamboCompositeProvider, null, children))))))));
32
35
  };
33
36
  export const TamboContext = createContext({});
34
37
  /**
@@ -44,12 +47,14 @@ export const TamboCompositeProvider = ({ children, }) => {
44
47
  const queryClient = useTamboQueryClient();
45
48
  const componentRegistry = useTamboComponent();
46
49
  const interactableComponents = useTamboInteractable();
50
+ const contextHelpers = useTamboContextHelpers();
47
51
  return (React.createElement(TamboContext.Provider, { value: {
48
52
  client,
49
53
  queryClient,
50
54
  ...componentRegistry,
51
55
  ...threads,
52
56
  ...interactableComponents,
57
+ ...contextHelpers,
53
58
  } }, children));
54
59
  };
55
60
  /**
@@ -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;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
+ {"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,EAEL,2BAA2B,EAE3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,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;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,aAAa,GAOtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAA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B,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 TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-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 * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\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 <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\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 const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\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"]}
@@ -2,6 +2,7 @@ import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import React, { PropsWithChildren } from "react";
3
3
  import { TamboComponent, TamboTool } from "../model/component-metadata";
4
4
  import { TamboThread } from "../model/tambo-thread";
5
+ import { TamboContextHelpersProviderProps } from "./tambo-context-helpers-provider";
5
6
  import { type TamboContextProps } from "./tambo-provider";
6
7
  /**
7
8
  * TamboStubProvider props - includes all the data that would normally be inferred
@@ -19,6 +20,8 @@ export interface TamboStubProviderProps extends Partial<TamboContextProps> {
19
20
  projectId?: string;
20
21
  /** Optional: Context key for thread list queries */
21
22
  contextKey?: string;
23
+ /** Optional: Configuration for which context helpers are enabled/disabled */
24
+ contextHelpers?: TamboContextHelpersProviderProps["contextHelpers"];
22
25
  }
23
26
  /**
24
27
  * The TamboStubProvider provides a way to use the Tambo API with static/stub data.
@@ -79,6 +82,7 @@ export interface TamboStubProviderProps extends Partial<TamboContextProps> {
79
82
  * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)
80
83
  * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)
81
84
  * @param props.contextKey - Optional context key for thread list queries
85
+ * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled
82
86
  * @returns The TamboStubProvider component
83
87
  */
84
88
  export declare const TamboStubProvider: React.FC<PropsWithChildren<TamboStubProviderProps>>;
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAO1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2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AE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;CACrE;AAsID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAsH1C,CAAC"}
@@ -4,6 +4,7 @@ import React, { useEffect } from "react";
4
4
  import { GenerationStage } from "../model/generate-component-response";
5
5
  import { TamboClientContext } from "./tambo-client-provider";
6
6
  import { TamboComponentProvider, } from "./tambo-component-provider";
7
+ import { TamboContextHelpersProvider, } from "./tambo-context-helpers-provider";
7
8
  import { TamboCompositeProvider, } from "./tambo-provider";
8
9
  import { TamboRegistryContext } from "./tambo-registry-provider";
9
10
  import { TamboThreadContext, } from "./tambo-thread-provider";
@@ -149,9 +150,10 @@ const createDefaultCallbacks = () => ({
149
150
  * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)
150
151
  * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)
151
152
  * @param props.contextKey - Optional context key for thread list queries
153
+ * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled
152
154
  * @returns The TamboStubProvider component
153
155
  */
154
- export const TamboStubProvider = ({ children, thread, components = [], tools = [], threads, projectId, contextKey, ...overrides }) => {
156
+ export const TamboStubProvider = ({ children, thread, components = [], tools = [], threads, projectId, contextKey, contextHelpers, ...overrides }) => {
155
157
  const defaults = createDefaultCallbacks();
156
158
  // Create stub client and queryClient
157
159
  const stubClient = {};
@@ -209,7 +211,8 @@ export const TamboStubProvider = ({ children, thread, components = [], tools = [
209
211
  return (React.createElement(TamboStubClientProvider, { client: stubClient, queryClient: stubQueryClient, threads: threads, projectId: resolvedProjectId, contextKey: contextKey },
210
212
  React.createElement(TamboStubRegistryProvider, { componentList: componentList, toolRegistry: toolRegistry, componentToolAssociations: componentToolAssociations, registerComponent: componentContextProps.registerComponent, registerTool: componentContextProps.registerTool, registerTools: componentContextProps.registerTools, addToolAssociation: componentContextProps.addToolAssociation },
211
213
  React.createElement(TamboStubThreadProvider, { ...threadContextProps },
212
- React.createElement(TamboComponentProvider, null,
213
- React.createElement(TamboCompositeProvider, null, children))))));
214
+ React.createElement(TamboContextHelpersProvider, { contextHelpers: contextHelpers },
215
+ React.createElement(TamboComponentProvider, null,
216
+ React.createElement(TamboCompositeProvider, null, children)))))));
214
217
  };
215
218
  //# sourceMappingURL=tambo-stubs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,GAEvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACL,kBAAkB,GAEnB,MAAM,yBAAyB,CAAC;AAoBjC;;;GAGG;AACH,MAAM,uBAAuB,GAQzB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,4DAA4D;IAC5D,SAAS,CAAC,G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,YAAY,IAAI,QAAQ,CAAC,YAAY;QAC7D,aAAa,EAAE,SAAS,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa;QAChE,kBAAkB,EAChB,SAAS,CAAC,kBAAkB,IAAI,QAAQ,CAAC,kBAAkB;KAC9D,CAAC;IAEF,OAAO,CACL,oBAAC,uBAAuB,IACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU;QAEtB,oBAAC,yBAAyB,IACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,yBAAyB,EAAE,yBAAyB,EACpD,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAC1D,YAAY,EAAE,qBAAqB,CAAC,YAAY,EAChD,aAAa,EAAE,qBAAqB,CAAC,aAAa,EAClD,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;YAE5D,oBAAC,uBAAuB,OAAK,kBAAkB;gBAC7C,oBAAC,sBAAsB;oBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACD,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({ children, client, queryClient, threads, projectId, contextKey }) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n inputValue: overrides.inputValue ?? \"\",\n streaming: overrides.streaming ?? true,\n setInputValue: overrides.setInputValue ?? defaults.setInputValue,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n generationStage: overrides.generationStage ?? GenerationStage.IDLE,\n generationStatusMessage: overrides.generationStatusMessage ?? \"\",\n isIdle: overrides.isIdle ?? true,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
1
+ {"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,2BAA2B,GAE5B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,sBAAsB,GAEvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACL,kBAAkB,GAEnB,MAAM,yBAAyB,CAAC;AAsBjC;;;GAGG;AACH,MAAM,uBAAuB,GAQzB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,4DAA4D;IAC5D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,kCAAkC;YAClC,WAAW,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;YAEnD,2FAA2F;YAC3F,WAAW,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE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ChB,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU;QAEtB,oBAAC,yBAAyB,IACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,yBAAyB,EAAE,yBAAyB,EACpD,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAC1D,YAAY,EAAE,qBAAqB,CAAC,YAAY,EAChD,aAAa,EAAE,qBAAqB,CAAC,aAAa,EAClD,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;YAE5D,oBAAC,uBAAuB,OAAK,kBAAkB;gBAC7C,oBAAC,2BAA2B,IAAC,cAAc,EAAE,cAAc;oBACzD,oBAAC,sBAAsB;wBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACG,CACN,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({ children, client, queryClient, threads, projectId, contextKey }) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n inputValue: overrides.inputValue ?? \"\",\n streaming: overrides.streaming ?? true,\n setInputValue: overrides.setInputValue ?? defaults.setInputValue,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n generationStage: overrides.generationStage ?? GenerationStage.IDLE,\n generationStatusMessage: overrides.generationStatusMessage ?? \"\",\n isIdle: overrides.isIdle ?? true,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\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,M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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;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACzC,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,CAkuB5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC"}
@@ -3,9 +3,10 @@ import { advanceStream } from "@tambo-ai/typescript-sdk";
3
3
  import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
4
4
  import { GenerationStage, isIdleStage, } from "../model/generate-component-response";
5
5
  import { renderComponentIntoMessage } from "../util/generate-component";
6
- import { getAvailableComponents, getSystemContext, getUnassociatedTools, mapTamboToolToContextTool, } from "../util/registry";
6
+ import { getAvailableComponents, getUnassociatedTools, mapTamboToolToContextTool, } from "../util/registry";
7
7
  import { handleToolCall } from "../util/tool-caller";
8
8
  import { useTamboClient } from "./tambo-client-provider";
9
+ import { useTamboContextHelpers } from "./tambo-context-helpers-provider";
9
10
  import { useTamboRegistry } from "./tambo-registry-provider";
10
11
  /**
11
12
  * This is a stub entry for when the thread is not yet created, the first time
@@ -95,6 +96,7 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
95
96
  });
96
97
  const client = useTamboClient();
97
98
  const { componentList, toolRegistry, componentToolAssociations } = useTamboRegistry();
99
+ const { getAdditionalContext } = useTamboContextHelpers();
98
100
  const [inputValue, setInputValue] = useState("");
99
101
  const [ignoreResponse, setIgnoreResponse] = useState(false);
100
102
  const ignoreResponseRef = useRef(ignoreResponse);
@@ -480,10 +482,16 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
480
482
  setIgnoreResponse(false);
481
483
  const { threadId = currentThreadId ?? PLACEHOLDER_THREAD.id, streamResponse = streaming, forceToolChoice, contextKey = currentThreadContextKey, additionalContext, } = options;
482
484
  updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);
485
+ // Get additional context from enabled helpers
486
+ const helperContexts = await getAdditionalContext();
487
+ // Combine all contexts
483
488
  const combinedContext = {
484
- system: getSystemContext(),
485
489
  ...(additionalContext ?? {}),
486
490
  };
491
+ // Add helper contexts to combinedContext
492
+ for (const helperContext of helperContexts) {
493
+ combinedContext[helperContext.name] = helperContext.context;
494
+ }
487
495
  addThreadMessage({
488
496
  content: [{ type: "text", text: message }],
489
497
  renderedComponent: null,
@@ -583,6 +591,7 @@ export const TamboThreadProvider = ({ children, streaming = true }) => {
583
591
  updateThreadStatus,
584
592
  handleAdvanceStream,
585
593
  streaming,
594
+ getAdditionalContext,
586
595
  ]);
587
596
  return (React.createElement(TamboThreadContext.Provider, { value: {
588
597
  thread: currentThread,
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-th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jC,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 getSystemContext,\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 additionalContext?: Record<string, any>;\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\n const chatMessage: TamboThreadMessage = {\n ...message,\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 additionalContext?: Record<string, any>;\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? PLACEHOLDER_THREAD.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey = currentThreadContextKey,\n additionalContext,\n } = options;\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n\n const combinedContext = {\n system: getSystemContext(),\n ...(additionalContext ?? {}),\n };\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 additionalContext: combinedContext,\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 additionalContext: combinedContext,\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"]}
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,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,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAmD7D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC7C,EAAE,EAAE,aAAa;IACjB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAA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CAChB,eAAe,CAAC,kBAAkB,CAAC,QAAQ,EAC3C,eAAe,CAAC,QAAQ,CACzB,CAAC;QACF,OAAO,YAAY,CAAC;IACtB,CAAC,EACD;QACE,aAAa;QACb,YAAY;QACZ,yBAAyB;QACzB,eAAe;QACf,uBAAuB;QACvB,mBAAmB;QACnB,gBAAgB;QAChB,MAAM;QACN,mBAAmB;QACnB,kBAAkB;QAClB,mBAAmB;QACnB,SAAS;QACT,oBAAoB;KACrB,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,MAAM,EAAE,aAAa;YACrB,mBAAmB;YACnB,cAAc;YACd,gBAAgB;YAChB,kBAAkB;YAClB,gBAAgB;YAChB,mBAAmB;YACnB,UAAU;YACV,aAAa;YACb,iBAAiB;YACjB,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 getUnassociatedTools,\n mapTamboToolToContextTool,\n} from \"../util/registry\";\nimport { handleToolCall } from \"../util/tool-caller\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-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 additionalContext?: Record<string, any>;\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 { getAdditionalContext } = useTamboContextHelpers();\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\n const chatMessage: TamboThreadMessage = {\n ...message,\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 additionalContext?: Record<string, any>;\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? PLACEHOLDER_THREAD.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey = currentThreadContextKey,\n additionalContext,\n } = options;\n updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);\n\n // Get additional context from enabled helpers\n const helperContexts = await getAdditionalContext();\n\n // Combine all contexts\n const combinedContext: Record<string, any> = {\n ...(additionalContext ?? {}),\n };\n\n // Add helper contexts to combinedContext\n for (const helperContext of helperContexts) {\n combinedContext[helperContext.name] = helperContext.context;\n }\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 additionalContext: combinedContext,\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 additionalContext: combinedContext,\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 getAdditionalContext,\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"]}
@@ -28,14 +28,6 @@ export declare const convertPropsToJsonSchema: (component: RegisteredComponent)
28
28
  * @returns The component registration information
29
29
  */
30
30
  export declare const getComponentFromRegistry: (componentName: string, componentRegistry: ComponentRegistry) => RegisteredComponent;
31
- /**
32
- * Get the client context for the current thread, such as the current time in the user's timezone
33
- * @returns a string of context additions that will be added to the prompt when the thread is advanced.
34
- */
35
- export declare const getSystemContext: () => {
36
- localTime: string;
37
- timezone: string;
38
- };
39
31
  /**
40
32
  * Map a Tambo tool to a context tool
41
33
  * @param tool - The tool to map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAGjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,SAAS,EAKX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AASF;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;CAE5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAGjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,SAAS,EAKX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
@@ -68,19 +68,6 @@ export const getComponentFromRegistry = (componentName, componentRegistry) => {
68
68
  }
69
69
  return componentEntry;
70
70
  };
71
- const getDefaultContextObject = () => {
72
- return {
73
- localTime: new Date().toLocaleString(),
74
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
75
- };
76
- };
77
- /**
78
- * Get the client context for the current thread, such as the current time in the user's timezone
79
- * @returns a string of context additions that will be added to the prompt when the thread is advanced.
80
- */
81
- export const getSystemContext = () => {
82
- return getDefaultContextObject();
83
- };
84
71
  /**
85
72
  * Map a Tambo tool to a context tool
86
73
  * @param tool - The tool to map