@tambo-ai/react 0.56.0 → 0.58.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 (86) hide show
  1. package/README.md +36 -0
  2. package/dist/hooks/react-query-hooks.d.ts +4 -4
  3. package/dist/hooks/react-query-hooks.js +4 -4
  4. package/dist/hooks/react-query-hooks.js.map +1 -1
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  10. package/dist/mcp/tambo-mcp-provider.js +9 -0
  11. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  12. package/dist/model/component-metadata.d.ts +7 -0
  13. package/dist/model/component-metadata.d.ts.map +1 -1
  14. package/dist/model/component-metadata.js.map +1 -1
  15. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.d.ts +2 -0
  16. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.d.ts.map +1 -0
  17. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js +179 -0
  18. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -0
  19. package/dist/providers/index.d.ts +1 -1
  20. package/dist/providers/index.d.ts.map +1 -1
  21. package/dist/providers/index.js.map +1 -1
  22. package/dist/providers/tambo-provider.d.ts +1 -0
  23. package/dist/providers/tambo-provider.d.ts.map +1 -1
  24. package/dist/providers/tambo-provider.js +3 -2
  25. package/dist/providers/tambo-provider.js.map +1 -1
  26. package/dist/providers/tambo-thread-provider.d.ts +13 -0
  27. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  28. package/dist/providers/tambo-thread-provider.js +67 -23
  29. package/dist/providers/tambo-thread-provider.js.map +1 -1
  30. package/dist/testing/tools.d.ts +1 -0
  31. package/dist/testing/tools.d.ts.map +1 -1
  32. package/dist/util/__tests__/content-parts.test.d.ts +2 -0
  33. package/dist/util/__tests__/content-parts.test.d.ts.map +1 -0
  34. package/dist/util/__tests__/content-parts.test.js +47 -0
  35. package/dist/util/__tests__/content-parts.test.js.map +1 -0
  36. package/dist/util/content-parts.d.ts +19 -0
  37. package/dist/util/content-parts.d.ts.map +1 -0
  38. package/dist/util/content-parts.js +40 -0
  39. package/dist/util/content-parts.js.map +1 -0
  40. package/dist/util/tool-caller.d.ts +4 -3
  41. package/dist/util/tool-caller.d.ts.map +1 -1
  42. package/dist/util/tool-caller.js +9 -5
  43. package/dist/util/tool-caller.js.map +1 -1
  44. package/esm/hooks/react-query-hooks.d.ts +4 -4
  45. package/esm/hooks/react-query-hooks.js +4 -4
  46. package/esm/hooks/react-query-hooks.js.map +1 -1
  47. package/esm/index.d.ts +3 -2
  48. package/esm/index.d.ts.map +1 -1
  49. package/esm/index.js +1 -1
  50. package/esm/index.js.map +1 -1
  51. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  52. package/esm/mcp/tambo-mcp-provider.js +9 -0
  53. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  54. package/esm/model/component-metadata.d.ts +7 -0
  55. package/esm/model/component-metadata.d.ts.map +1 -1
  56. package/esm/model/component-metadata.js.map +1 -1
  57. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.d.ts +2 -0
  58. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.d.ts.map +1 -0
  59. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js +174 -0
  60. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -0
  61. package/esm/providers/index.d.ts +1 -1
  62. package/esm/providers/index.d.ts.map +1 -1
  63. package/esm/providers/index.js.map +1 -1
  64. package/esm/providers/tambo-provider.d.ts +1 -0
  65. package/esm/providers/tambo-provider.d.ts.map +1 -1
  66. package/esm/providers/tambo-provider.js +3 -2
  67. package/esm/providers/tambo-provider.js.map +1 -1
  68. package/esm/providers/tambo-thread-provider.d.ts +13 -0
  69. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  70. package/esm/providers/tambo-thread-provider.js +67 -23
  71. package/esm/providers/tambo-thread-provider.js.map +1 -1
  72. package/esm/testing/tools.d.ts +1 -0
  73. package/esm/testing/tools.d.ts.map +1 -1
  74. package/esm/util/__tests__/content-parts.test.d.ts +2 -0
  75. package/esm/util/__tests__/content-parts.test.d.ts.map +1 -0
  76. package/esm/util/__tests__/content-parts.test.js +45 -0
  77. package/esm/util/__tests__/content-parts.test.js.map +1 -0
  78. package/esm/util/content-parts.d.ts +19 -0
  79. package/esm/util/content-parts.d.ts.map +1 -0
  80. package/esm/util/content-parts.js +35 -0
  81. package/esm/util/content-parts.js.map +1 -0
  82. package/esm/util/tool-caller.d.ts +4 -3
  83. package/esm/util/tool-caller.d.ts.map +1 -1
  84. package/esm/util/tool-caller.js +9 -5
  85. package/esm/util/tool-caller.js.map +1 -1
  86. package/package.json +6 -6
@@ -58,9 +58,10 @@ const tambo_thread_provider_1 = require("./tambo-thread-provider");
58
58
  * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)
59
59
  * @param props.contextKey - Optional context key to be used in the thread input provider
60
60
  * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
61
+ * @param props.initialMessages - Initial messages to be included in new threads
61
62
  * @returns The TamboProvider component
62
63
  */
63
- const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, streaming, contextHelpers, contextKey, onCallUnregisteredTool, }) => {
64
+ const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, streaming, contextHelpers, contextKey, initialMessages, onCallUnregisteredTool, }) => {
64
65
  // Should only be used in browser
65
66
  if (typeof window === "undefined") {
66
67
  console.error("TamboProvider must be used within a browser");
@@ -68,7 +69,7 @@ const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, envi
68
69
  return (react_1.default.createElement(tambo_client_provider_1.TamboClientProvider, { tamboUrl: tamboUrl, apiKey: apiKey, environment: environment, userToken: userToken },
69
70
  react_1.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, { components: components, tools: tools, onCallUnregisteredTool: onCallUnregisteredTool },
70
71
  react_1.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, { contextHelpers: contextHelpers },
71
- react_1.default.createElement(tambo_thread_provider_1.TamboThreadProvider, { streaming: streaming },
72
+ react_1.default.createElement(tambo_thread_provider_1.TamboThreadProvider, { streaming: streaming, initialMessages: initialMessages },
72
73
  react_1.default.createElement(tambo_thread_input_provider_1.TamboThreadInputProvider, { contextKey: contextKey },
73
74
  react_1.default.createElement(tambo_component_provider_1.TamboComponentProvider, null,
74
75
  react_1.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAE5E,mEAOiC;AACjC,yEAIoC;AACpC,qFAK0C;AAC1C,+EAGuC;AACvC,uEAGmC;AACnC,+EAGuC;AACvC,mEAMiC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,aAAa,GAQtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,sBAAsB,GACvB,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,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;QAEpB,8BAAC,+CAAqB,IACpB,UAAU,EAAE,UAAU,EACtB,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C;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\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 TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\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 * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n onCallUnregisteredTool,\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\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\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 isUpdatingToken = useIsTamboTokenUpdating();\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 isUpdatingToken,\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"]}
1
+ {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAE5E,mEAOiC;AACjC,yEAIoC;AACpC,qFAK0C;AAC1C,+EAGuC;AACvC,uEAGmC;AACnC,+EAGuC;AACvC,mEAMiC;AAEjC;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,aAAa,GAQtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,eAAe,EACf,sBAAsB,GACvB,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,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;QAEpB,8BAAC,+CAAqB,IACpB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,sBAAsB,EAAE,sBAAsB;YAE9C,8BAAC,4DAA2B,IAAC,cAAc,EAAE,cAAc;gBACzD,8BAAC,2CAAmB,IAClB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe;oBAEhC,8BAAC,sDAAwB,IAAC,UAAU,EAAE,UAAU;wBAC9C,8BAAC,iDAAsB;4BACrB,8BAAC,uDAAyB;gCACxB,8BAAC,8BAAsB,QAAE,QAAQ,CAA0B,CACjC,CACL,CACA,CACP,CACM,CACR,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAxDW,QAAA,aAAa,iBAwDxB;AASW,QAAA,YAAY,GAAG,IAAA,qBAAa,EACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAgC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,IAAA,sCAAc,GAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAA,sCAAc,GAAE,CAAC;IAChC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,MAAM,eAAe,GAAG,IAAA,+CAAuB,GAAE,CAAC;IAClD,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAEhD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,sBAAsB,0BA0BjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\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 TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\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 * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @param props.initialMessages - Initial messages to be included in new threads\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n initialMessages,\n onCallUnregisteredTool,\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\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider\n streaming={streaming}\n initialMessages={initialMessages}\n >\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\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 isUpdatingToken = useIsTamboTokenUpdating();\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 isUpdatingToken,\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"]}
@@ -65,9 +65,21 @@ export interface CombinedTamboThreadContextProps extends TamboThreadContextProps
65
65
  */
66
66
  export declare const PLACEHOLDER_THREAD: TamboThread;
67
67
  export declare const TamboThreadContext: React.Context<TamboThreadContextProps>;
68
+ export type InitialTamboThreadMessage = Pick<TamboThreadMessage, "role" | "content"> & {
69
+ /** Optional ID - will be auto-generated if not provided */
70
+ id?: string;
71
+ /** Optional creation timestamp - will be auto-generated if not provided */
72
+ createdAt?: string;
73
+ /** Optional additional context to include with the message */
74
+ additionalContext?: Record<string, any>;
75
+ /** Optional component state - will default to empty object if not provided */
76
+ componentState?: Record<string, any>;
77
+ };
68
78
  export interface TamboThreadProviderProps {
69
79
  /** Whether to stream the response */
70
80
  streaming?: boolean;
81
+ /** Initial messages to be included in new threads */
82
+ initialMessages?: InitialTamboThreadMessage[];
71
83
  }
72
84
  /**
73
85
  * The TamboThreadProvider is a React provider that provides a thread context
@@ -75,6 +87,7 @@ export interface TamboThreadProviderProps {
75
87
  * @param props - The props for the TamboThreadProvider
76
88
  * @param props.children - The children to wrap
77
89
  * @param props.streaming - Whether to stream the response by default. Defaults to true.
90
+ * @param props.initialMessages - Initial messages to be included in new threads
78
91
  * @returns The TamboThreadProvider component
79
92
  */
80
93
  export declare const TamboThreadProvider: React.FC<PropsWithChildren<TamboThreadProviderProps>>;
@@ -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,kBA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,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,eAAe,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CACxC,iBAAiB,CAAC,wBAAwB,CAAC,CAi2B5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAO,gCAU1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,+BAgBjC,CAAC"}
@@ -38,6 +38,7 @@ exports.useTamboThread = exports.useTamboGenerationStage = exports.TamboThreadPr
38
38
  const typescript_sdk_1 = require("@tambo-ai/typescript-sdk");
39
39
  const react_1 = __importStar(require("react"));
40
40
  const generate_component_response_1 = require("../model/generate-component-response");
41
+ const content_parts_1 = require("../util/content-parts");
41
42
  const generate_component_1 = require("../util/generate-component");
42
43
  const registry_1 = require("../util/registry");
43
44
  const tool_caller_1 = require("../util/tool-caller");
@@ -139,11 +140,27 @@ exports.TamboThreadContext = (0, react_1.createContext)({
139
140
  * @param props - The props for the TamboThreadProvider
140
141
  * @param props.children - The children to wrap
141
142
  * @param props.streaming - Whether to stream the response by default. Defaults to true.
143
+ * @param props.initialMessages - Initial messages to be included in new threads
142
144
  * @returns The TamboThreadProvider component
143
145
  */
144
- const TamboThreadProvider = ({ children, streaming = true }) => {
146
+ const TamboThreadProvider = ({ children, streaming = true, initialMessages = [] }) => {
147
+ // Create placeholder thread with initial messages
148
+ const placeholderThread = (0, react_1.useMemo)(() => ({
149
+ id: "placeholder",
150
+ messages: initialMessages.map((msg) => ({
151
+ ...msg,
152
+ id: msg.id ?? crypto.randomUUID(),
153
+ threadId: "placeholder",
154
+ createdAt: msg.createdAt ?? new Date().toISOString(),
155
+ componentState: msg.componentState ?? {},
156
+ })),
157
+ createdAt: "",
158
+ projectId: "",
159
+ updatedAt: "",
160
+ metadata: {},
161
+ }), [initialMessages]);
145
162
  const [threadMap, setThreadMap] = (0, react_1.useState)({
146
- [exports.PLACEHOLDER_THREAD.id]: exports.PLACEHOLDER_THREAD,
163
+ [placeholderThread.id]: placeholderThread,
147
164
  });
148
165
  const client = (0, tambo_client_provider_1.useTamboClient)();
149
166
  const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
@@ -151,7 +168,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
151
168
  const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
152
169
  const [ignoreResponse, setIgnoreResponse] = (0, react_1.useState)(false);
153
170
  const ignoreResponseRef = (0, react_1.useRef)(ignoreResponse);
154
- const [currentThreadId, setCurrentThreadId] = (0, react_1.useState)(exports.PLACEHOLDER_THREAD.id);
171
+ const [currentThreadId, setCurrentThreadId] = (0, react_1.useState)(placeholderThread.id);
155
172
  const currentThread = threadMap[currentThreadId];
156
173
  // Generation stage props for GenerationStageProvider
157
174
  const currentGenerationStage = currentThread?.generationStage ?? generate_component_response_1.GenerationStage.IDLE;
@@ -221,11 +238,11 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
221
238
  }, [client.beta.threads, componentList, currentMessageCache]);
222
239
  (0, react_1.useEffect)(() => {
223
240
  if (currentThreadId &&
224
- currentThreadId !== exports.PLACEHOLDER_THREAD.id &&
241
+ currentThreadId !== placeholderThread.id &&
225
242
  !threadMap[currentThreadId]) {
226
243
  fetchThread(currentThreadId);
227
244
  }
228
- }, [currentThreadId, fetchThread, threadMap]);
245
+ }, [currentThreadId, fetchThread, threadMap, placeholderThread.id]);
229
246
  const addThreadMessage = (0, react_1.useCallback)(async (message, sendToServer = true, createdAt = new Date().toISOString()) => {
230
247
  if (!currentThread) {
231
248
  console.warn("Cannot add messages if we do not have a current thread");
@@ -306,14 +323,14 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
306
323
  }
307
324
  }, [client.beta.threads.messages]);
308
325
  const startNewThread = (0, react_1.useCallback)(() => {
309
- setCurrentThreadId(exports.PLACEHOLDER_THREAD.id);
326
+ setCurrentThreadId(placeholderThread.id);
310
327
  setThreadMap((prevMap) => {
311
328
  return {
312
329
  ...prevMap,
313
- [exports.PLACEHOLDER_THREAD.id]: exports.PLACEHOLDER_THREAD,
330
+ [placeholderThread.id]: placeholderThread,
314
331
  };
315
332
  });
316
- }, []);
333
+ }, [placeholderThread]);
317
334
  const updateThreadName = (0, react_1.useCallback)(async (name, threadId) => {
318
335
  threadId ??= currentThreadId;
319
336
  setThreadMap((prevMap) => {
@@ -322,17 +339,22 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
322
339
  }
323
340
  return { ...prevMap, [threadId]: { ...prevMap[threadId], name } };
324
341
  });
325
- if (threadId !== exports.PLACEHOLDER_THREAD.id) {
342
+ if (threadId !== placeholderThread.id) {
326
343
  const currentProject = await client.beta.projects.getCurrent();
327
344
  await client.beta.threads.update(threadId, {
328
345
  name,
329
346
  projectId: currentProject.id,
330
347
  });
331
348
  }
332
- }, [currentThreadId, client.beta.projects, client.beta.threads]);
349
+ }, [
350
+ currentThreadId,
351
+ client.beta.projects,
352
+ client.beta.threads,
353
+ placeholderThread.id,
354
+ ]);
333
355
  const generateThreadName = (0, react_1.useCallback)(async (threadId) => {
334
356
  threadId ??= currentThreadId;
335
- if (threadId === exports.PLACEHOLDER_THREAD.id) {
357
+ if (threadId === placeholderThread.id) {
336
358
  console.warn("Cannot generate name for empty thread");
337
359
  return threadMap[threadId];
338
360
  }
@@ -350,9 +372,9 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
350
372
  };
351
373
  });
352
374
  return threadWithGeneratedName;
353
- }, [client.beta.threads, currentThreadId, threadMap]);
375
+ }, [client.beta.threads, currentThreadId, threadMap, placeholderThread.id]);
354
376
  const switchCurrentThread = (0, react_1.useCallback)(async (threadId, fetch = true) => {
355
- if (threadId === exports.PLACEHOLDER_THREAD.id) {
377
+ if (threadId === placeholderThread.id) {
356
378
  console.warn("Switching to placeholder thread, may be a bug.");
357
379
  return;
358
380
  }
@@ -365,7 +387,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
365
387
  const updatedThreadMap = {
366
388
  ...prevMap,
367
389
  [threadId]: {
368
- ...prevMap[exports.PLACEHOLDER_THREAD.id],
390
+ ...prevMap[placeholderThread.id],
369
391
  id: threadId,
370
392
  },
371
393
  };
@@ -374,7 +396,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
374
396
  if (fetch) {
375
397
  await fetchThread(threadId);
376
398
  }
377
- }, [fetchThread]);
399
+ }, [fetchThread, placeholderThread]);
378
400
  const updateThreadStatus = (0, react_1.useCallback)((threadId, stage, statusMessage) => {
379
401
  setThreadMap((prevMap) => {
380
402
  const updatedThreadMap = {
@@ -562,7 +584,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
562
584
  ]);
563
585
  const sendThreadMessage = (0, react_1.useCallback)(async (message, options = {}) => {
564
586
  setIgnoreResponse(false);
565
- const { threadId = currentThreadId ?? exports.PLACEHOLDER_THREAD.id, streamResponse = streaming, forceToolChoice, contextKey, additionalContext, content, } = options;
587
+ const { threadId = currentThreadId ?? placeholderThread.id, streamResponse = streaming, forceToolChoice, contextKey, additionalContext, content, } = options;
566
588
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.FETCHING_CONTEXT);
567
589
  // Get additional context from enabled helpers
568
590
  const helperContexts = await getAdditionalContext();
@@ -603,11 +625,19 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
603
625
  clientTools: unassociatedTools.map((tool) => (0, registry_1.mapTamboToolToContextTool)(tool)),
604
626
  forceToolChoice: forceToolChoice,
605
627
  toolCallCounts,
628
+ ...(threadId === placeholderThread.id &&
629
+ initialMessages.length > 0 && {
630
+ initialMessages: initialMessages.map((msg) => ({
631
+ content: msg.content,
632
+ role: msg.role,
633
+ additionalContext: msg.additionalContext,
634
+ })),
635
+ }),
606
636
  };
607
637
  if (streamResponse) {
608
638
  let advanceStreamResponse;
609
639
  try {
610
- advanceStreamResponse = await (0, typescript_sdk_1.advanceStream)(client, params, threadId === exports.PLACEHOLDER_THREAD.id ? undefined : threadId);
640
+ advanceStreamResponse = await (0, typescript_sdk_1.advanceStream)(client, params, threadId === placeholderThread.id ? undefined : threadId);
611
641
  }
612
642
  catch (error) {
613
643
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.ERROR);
@@ -623,7 +653,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
623
653
  }
624
654
  let advanceResponse;
625
655
  try {
626
- advanceResponse = await (threadId === exports.PLACEHOLDER_THREAD.id
656
+ advanceResponse = await (threadId === placeholderThread.id
627
657
  ? client.beta.threads.advance(params)
628
658
  : client.beta.threads.advanceByID(threadId, params));
629
659
  }
@@ -641,14 +671,12 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
641
671
  }
642
672
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.FETCHING_CONTEXT);
643
673
  const toolCallResponse = await (0, tool_caller_1.handleToolCall)(advanceResponse.responseMessageDto, toolRegistry, onCallUnregisteredTool);
644
- const toolResponseString = typeof toolCallResponse.result === "string"
645
- ? toolCallResponse.result
646
- : JSON.stringify(toolCallResponse.result);
674
+ const contentParts = convertToolResponse(toolCallResponse);
647
675
  const toolCallResponseParams = {
648
676
  ...params,
649
677
  messageToAppend: {
650
678
  ...params.messageToAppend,
651
- content: [{ type: "text", text: toolResponseString }],
679
+ content: contentParts,
652
680
  role: "tool",
653
681
  actionType: "tool_response",
654
682
  component: advanceResponse.responseMessageDto.component,
@@ -667,7 +695,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
667
695
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.HYDRATING_COMPONENT);
668
696
  addThreadMessage({
669
697
  threadId: threadId,
670
- content: [{ type: "text", text: toolResponseString }],
698
+ content: contentParts,
671
699
  role: "tool",
672
700
  id: crypto.randomUUID(),
673
701
  createdAt: new Date().toISOString(),
@@ -709,6 +737,8 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
709
737
  handleAdvanceStream,
710
738
  streaming,
711
739
  getAdditionalContext,
740
+ placeholderThread.id,
741
+ initialMessages,
712
742
  onCallUnregisteredTool,
713
743
  refetchThreadsList,
714
744
  ]);
@@ -760,4 +790,18 @@ const useTamboThread = () => {
760
790
  };
761
791
  };
762
792
  exports.useTamboThread = useTamboThread;
793
+ function convertToolResponse(toolCallResponse) {
794
+ // If the tool call errored, surface that as text so the model reliably sees the error
795
+ if (toolCallResponse.error) {
796
+ return [{ type: "text", text: (0, content_parts_1.toText)(toolCallResponse.result) }];
797
+ }
798
+ // Use custom transform when available
799
+ if (toolCallResponse.tamboTool?.transformToContent) {
800
+ return toolCallResponse.tamboTool.transformToContent(
801
+ // result shape is user-defined; let the transform decide how to handle it
802
+ toolCallResponse.result);
803
+ }
804
+ // Default fallback to stringified text
805
+ return [{ type: "text", text: (0, content_parts_1.toText)(toolCallResponse.result) }];
806
+ }
763
807
  //# sourceMappingURL=tambo-thread-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,6DAAkE;AAElE,+CASe;AACf,sFAI8C;AAE9C,mEAAwE;AACxE,+CAI0B;AAC1B,qDAAqD;AACrD,mEAA8E;AAC9E,qFAA0E;AAC1E,uEAA6D;AAS7D,MAAM,2BAA2B,GAAG,IAAA,qBAAa,EAE/C,SAAS,CAAC,CAAC;AAOb;;;;;;;;GAQG;AACI,MAAM,4BAA4B,GAErC,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,yCAAW,EAAC,eAAe,CAAC,CAAC;IAE5C,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IAED,OAAO,sBAAsB,CAAC;AAChC,CAAC,CAAC;AAVW,QAAA,uBAAuB,2BAUlC;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAG,GAAoC,EAAE;IAClE,MAAM,aAAa,GAAG,IAAA,kBAAU,EAAC,0BAAkB,CAAC,CAAC;IACrD,MAAM,sBAAsB,GAAG,IAAA,kBAAU,EAAC,2BAA2B,CAAC,CAAC;IAEvE,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO;QACL,GAAG,aAAa;QAChB,GAAG,sBAAsB;KAC1B,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB","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, useTamboQueryClient } from \"./tambo-client-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\n// Generation Stage Context - separate from thread context to prevent re-renders\nexport interface TamboGenerationStageContextProps {\n generationStage: GenerationStage;\n generationStatusMessage: string;\n isIdle: boolean;\n}\n\nconst TamboGenerationStageContext = createContext<\n TamboGenerationStageContextProps | undefined\n>(undefined);\n\ninterface TamboGenerationStageProviderProps {\n generationStage: GenerationStage;\n statusMessage: string;\n}\n\n/**\n *\n * This provider is used to provide the generation stage context to the descendants of the provider.\n * @param props - The props for the GenerationStageProvider\n * @param props.children - The children to wrap\n * @param props.generationStage - The generation stage to provide\n * @param props.statusMessage - The status message to provide\n * @returns The GenerationStageProvider component\n */\nexport const TamboGenerationStageProvider: React.FC<\n PropsWithChildren<TamboGenerationStageProviderProps>\n> = ({ children, generationStage, statusMessage }) => {\n const isIdle = isIdleStage(generationStage);\n\n const contextValue = useMemo(() => {\n return {\n generationStage,\n generationStatusMessage: statusMessage,\n isIdle,\n };\n }, [generationStage, statusMessage, isIdle]);\n\n return (\n <TamboGenerationStageContext.Provider value={contextValue}>\n {children}\n </TamboGenerationStageContext.Provider>\n );\n};\n\n// Type for partial message updates that requires threadId\ntype PartialTamboThreadMessageWithThreadId = Partial<TamboThreadMessage> & {\n threadId: string;\n};\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: PartialTamboThreadMessageWithThreadId,\n sendToServer: boolean,\n ) => Promise<void>;\n /** Cancel a thread */\n cancel: (threadId?: string) => Promise<void>;\n /** Whether the thread is streaming */\n streaming: boolean;\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 content?: TamboAI.Beta.Threads.ChatCompletionContentPart[];\n },\n ) => Promise<TamboThreadMessage>;\n}\n\n// Combined context interface that includes generation stage fields\nexport interface CombinedTamboThreadContextProps\n extends TamboThreadContextProps,\n TamboGenerationStageContextProps {}\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 streaming: true,\n /**\n *\n */\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n /**\n *\n */\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented\");\n },\n /**\n *\n */\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 queryClient = useTamboQueryClient();\n const {\n componentList,\n toolRegistry,\n componentToolAssociations,\n onCallUnregisteredTool,\n } = useTamboRegistry();\n const { getAdditionalContext } = useTamboContextHelpers();\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 // Generation stage props for GenerationStageProvider\n const currentGenerationStage =\n (currentThread?.generationStage as GenerationStage) ?? GenerationStage.IDLE;\n const currentStatusMessage = currentThread?.statusMessage ?? \"\";\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 refetchThreadsList = useCallback(\n async (threadId: string, contextKey: string | undefined) => {\n try {\n const currentProject = await client.beta.projects.getCurrent();\n\n const optimisticThread = {\n ...PLACEHOLDER_THREAD,\n id: threadId,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n\n queryClient.setQueryData(\n [\"threads\", currentProject.id, contextKey],\n (old: TamboAI.Beta.Threads.ThreadsOffsetAndLimit | undefined) => {\n return {\n ...old,\n items: [optimisticThread, ...(old?.items ?? [])],\n };\n },\n );\n\n await queryClient.invalidateQueries({\n queryKey: [\"threads\"],\n });\n } catch (error) {\n console.warn(\"Failed to refetch threads list:\", error);\n }\n },\n [client.beta.projects, queryClient],\n );\n\n const fetchThread = useCallback(\n async (threadId: string) => {\n const thread = await client.beta.threads.retrieve(threadId);\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: PartialTamboThreadMessageWithThreadId,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n setThreadMap((prevMap) => {\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n // Merge the partial update with the existing message\n const updatedMessage: TamboThreadMessage = {\n ...msg,\n ...message,\n id: msg.id,\n createdAt: message.createdAt ?? msg.createdAt ?? createdAt,\n };\n return updatedMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n\n if (sendToServer && message.content && message.role) {\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: message.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\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\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 const currentGenerationStage =\n currentThread?.generationStage ?? GenerationStage.IDLE;\n if (isIdleStage(currentGenerationStage as GenerationStage)) {\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, currentThread?.generationStage],\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 contextKey?: 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 onCallUnregisteredTool,\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 contextKey,\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 const wasPlaceholderThread =\n currentThreadId === PLACEHOLDER_THREAD.id;\n await switchCurrentThread(chunk.responseMessageDto.threadId, false);\n\n // If we're switching from placeholder to a real thread\n // this means a new thread was created, so refetch the threads list\n if (wasPlaceholderThread) {\n await refetchThreadsList(\n chunk.responseMessageDto.threadId,\n contextKey,\n );\n }\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 currentThreadId,\n onCallUnregisteredTool,\n refetchThreadsList,\n switchCurrentThread,\n toolRegistry,\n updateThreadMessage,\n updateThreadStatus,\n ],\n );\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 content?: TamboAI.Beta.Threads.ChatCompletionContentPart[];\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? PLACEHOLDER_THREAD.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey,\n additionalContext,\n content,\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 // Use provided content or build simple text message\n const messageContent = content ?? [\n { type: \"text\" as const, text: message },\n ];\n\n addThreadMessage(\n {\n content: messageContent as any,\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: messageContent as any,\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 let advanceStreamResponse: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>;\n try {\n advanceStreamResponse = await advanceStream(\n client,\n params,\n threadId === PLACEHOLDER_THREAD.id ? undefined : threadId,\n );\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n try {\n return await handleAdvanceStream(\n advanceStreamResponse,\n params,\n threadId,\n contextKey,\n );\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n }\n\n let advanceResponse: TamboAI.Beta.Threads.ThreadAdvanceResponse;\n try {\n advanceResponse = await (threadId === PLACEHOLDER_THREAD.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceByID(threadId, params));\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n\n //handle tool calls\n try {\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 onCallUnregisteredTool,\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 } catch (error) {\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.ERROR,\n );\n throw error;\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n const wasPlaceholderThread = currentThreadId === PLACEHOLDER_THREAD.id;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n\n // If we're switching from placeholder to a real thread\n // this means a new thread was created, so refetch the threads list\n if (wasPlaceholderThread) {\n await refetchThreadsList(\n advanceResponse.responseMessageDto.threadId,\n contextKey,\n );\n }\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.COMPLETE,\n );\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThreadId,\n switchCurrentThread,\n addThreadMessage,\n client,\n updateThreadMessage,\n updateThreadStatus,\n handleAdvanceStream,\n streaming,\n getAdditionalContext,\n onCallUnregisteredTool,\n refetchThreadsList,\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 streaming,\n cancel,\n sendThreadMessage,\n }}\n >\n <TamboGenerationStageProvider\n generationStage={currentGenerationStage}\n statusMessage={currentStatusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * The useTamboGenerationStage hook provides access to the generation stage context\n * to the descendants of the TamboThreadProvider.\n * @returns The generation stage context\n */\nexport const useTamboGenerationStage = (): TamboGenerationStageContextProps => {\n const generationStageContext = useContext(TamboGenerationStageContext);\n\n if (generationStageContext === undefined) {\n throw new Error(\n \"useTamboGenerationStage must be used within a TamboThreadProvider\",\n );\n }\n\n return generationStageContext;\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 = (): CombinedTamboThreadContextProps => {\n const threadContext = useContext(TamboThreadContext);\n const generationStageContext = useContext(TamboGenerationStageContext);\n\n if (threadContext === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n\n if (generationStageContext === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n\n return {\n ...threadContext,\n ...generationStageContext,\n };\n};\n"]}
1
+ {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,6DAAkE;AAElE,+CASe;AAEf,sFAI8C;AAE9C,yDAA+C;AAC/C,mEAAwE;AACxE,+CAI0B;AAC1B,qDAAqD;AACrD,mEAA8E;AAC9E,qFAA0E;AAC1E,uEAA6D;AAS7D,MAA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C,CAAC;IACrD,MAAM,sBAAsB,GAAG,IAAA,kBAAU,EAAC,2BAA2B,CAAC,CAAC;IAEvE,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO;QACL,GAAG,aAAa;QAChB,GAAG,sBAAsB;KAC1B,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB;AAEF,SAAS,mBAAmB,CAAC,gBAI5B;IACC,sFAAsF;IACtF,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAA,sBAAM,EAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,sCAAsC;IACtC,IAAI,gBAAgB,CAAC,SAAS,EAAE,kBAAkB,EAAE,CAAC;QACnD,OAAO,gBAAgB,CAAC,SAAS,CAAC,kBAAkB;QAClD,0EAA0E;QAC1E,gBAAgB,CAAC,MAAa,CAC/B,CAAC;IACJ,CAAC;IAED,uCAAuC;IACvC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAA,sBAAM,EAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnE,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 { TamboTool } from \"../model/component-metadata\";\nimport {\n GenerationStage,\n isIdleStage,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { toText } from \"../util/content-parts\";\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, useTamboQueryClient } from \"./tambo-client-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\n// Generation Stage Context - separate from thread context to prevent re-renders\nexport interface TamboGenerationStageContextProps {\n generationStage: GenerationStage;\n generationStatusMessage: string;\n isIdle: boolean;\n}\n\nconst TamboGenerationStageContext = createContext<\n TamboGenerationStageContextProps | undefined\n>(undefined);\n\ninterface TamboGenerationStageProviderProps {\n generationStage: GenerationStage;\n statusMessage: string;\n}\n\n/**\n *\n * This provider is used to provide the generation stage context to the descendants of the provider.\n * @param props - The props for the GenerationStageProvider\n * @param props.children - The children to wrap\n * @param props.generationStage - The generation stage to provide\n * @param props.statusMessage - The status message to provide\n * @returns The GenerationStageProvider component\n */\nexport const TamboGenerationStageProvider: React.FC<\n PropsWithChildren<TamboGenerationStageProviderProps>\n> = ({ children, generationStage, statusMessage }) => {\n const isIdle = isIdleStage(generationStage);\n\n const contextValue = useMemo(() => {\n return {\n generationStage,\n generationStatusMessage: statusMessage,\n isIdle,\n };\n }, [generationStage, statusMessage, isIdle]);\n\n return (\n <TamboGenerationStageContext.Provider value={contextValue}>\n {children}\n </TamboGenerationStageContext.Provider>\n );\n};\n\n// Type for partial message updates that requires threadId\ntype PartialTamboThreadMessageWithThreadId = Partial<TamboThreadMessage> & {\n threadId: string;\n};\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: PartialTamboThreadMessageWithThreadId,\n sendToServer: boolean,\n ) => Promise<void>;\n /** Cancel a thread */\n cancel: (threadId?: string) => Promise<void>;\n /** Whether the thread is streaming */\n streaming: boolean;\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 content?: TamboAI.Beta.Threads.ChatCompletionContentPart[];\n },\n ) => Promise<TamboThreadMessage>;\n}\n\n// Combined context interface that includes generation stage fields\nexport interface CombinedTamboThreadContextProps\n extends TamboThreadContextProps,\n TamboGenerationStageContextProps {}\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 streaming: true,\n /**\n *\n */\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n /**\n *\n */\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented\");\n },\n /**\n *\n */\n cancel: () => {\n throw new Error(\"cancel not implemented\");\n },\n});\n\nexport type InitialTamboThreadMessage = Pick<\n TamboThreadMessage,\n \"role\" | \"content\"\n> & {\n /** Optional ID - will be auto-generated if not provided */\n id?: string;\n /** Optional creation timestamp - will be auto-generated if not provided */\n createdAt?: string;\n /** Optional additional context to include with the message */\n additionalContext?: Record<string, any>;\n /** Optional component state - will default to empty object if not provided */\n componentState?: Record<string, any>;\n};\n\nexport interface TamboThreadProviderProps {\n /** Whether to stream the response */\n streaming?: boolean;\n /** Initial messages to be included in new threads */\n initialMessages?: InitialTamboThreadMessage[];\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 * @param props.initialMessages - Initial messages to be included in new threads\n * @returns The TamboThreadProvider component\n */\nexport const TamboThreadProvider: React.FC<\n PropsWithChildren<TamboThreadProviderProps>\n> = ({ children, streaming = true, initialMessages = [] }) => {\n // Create placeholder thread with initial messages\n const placeholderThread: TamboThread = useMemo(\n () => ({\n id: \"placeholder\",\n messages: initialMessages.map((msg) => ({\n ...msg,\n id: msg.id ?? crypto.randomUUID(),\n threadId: \"placeholder\",\n createdAt: msg.createdAt ?? new Date().toISOString(),\n componentState: msg.componentState ?? {},\n })),\n createdAt: \"\",\n projectId: \"\",\n updatedAt: \"\",\n metadata: {},\n }),\n [initialMessages],\n );\n\n const [threadMap, setThreadMap] = useState<Record<string, TamboThread>>({\n [placeholderThread.id]: placeholderThread,\n });\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const {\n componentList,\n toolRegistry,\n componentToolAssociations,\n onCallUnregisteredTool,\n } = useTamboRegistry();\n const { getAdditionalContext } = useTamboContextHelpers();\n const [ignoreResponse, setIgnoreResponse] = useState(false);\n const ignoreResponseRef = useRef(ignoreResponse);\n const [currentThreadId, setCurrentThreadId] = useState<string>(\n placeholderThread.id,\n );\n const currentThread: TamboThread | undefined = threadMap[currentThreadId];\n\n // Generation stage props for GenerationStageProvider\n const currentGenerationStage =\n (currentThread?.generationStage as GenerationStage) ?? GenerationStage.IDLE;\n const currentStatusMessage = currentThread?.statusMessage ?? \"\";\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 refetchThreadsList = useCallback(\n async (threadId: string, contextKey: string | undefined) => {\n try {\n const currentProject = await client.beta.projects.getCurrent();\n\n const optimisticThread = {\n ...PLACEHOLDER_THREAD,\n id: threadId,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n\n queryClient.setQueryData(\n [\"threads\", currentProject.id, contextKey],\n (old: TamboAI.Beta.Threads.ThreadsOffsetAndLimit | undefined) => {\n return {\n ...old,\n items: [optimisticThread, ...(old?.items ?? [])],\n };\n },\n );\n\n await queryClient.invalidateQueries({\n queryKey: [\"threads\"],\n });\n } catch (error) {\n console.warn(\"Failed to refetch threads list:\", error);\n }\n },\n [client.beta.projects, queryClient],\n );\n\n const fetchThread = useCallback(\n async (threadId: string) => {\n const thread = await client.beta.threads.retrieve(threadId);\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 !== placeholderThread.id &&\n !threadMap[currentThreadId]\n ) {\n fetchThread(currentThreadId);\n }\n }, [currentThreadId, fetchThread, threadMap, placeholderThread.id]);\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: PartialTamboThreadMessageWithThreadId,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n setThreadMap((prevMap) => {\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n // Merge the partial update with the existing message\n const updatedMessage: TamboThreadMessage = {\n ...msg,\n ...message,\n id: msg.id,\n createdAt: message.createdAt ?? msg.createdAt ?? createdAt,\n };\n return updatedMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n\n if (sendToServer && message.content && message.role) {\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: message.additionalContext,\n });\n }\n },\n [client.beta.threads.messages],\n );\n\n const startNewThread = useCallback(() => {\n setCurrentThreadId(placeholderThread.id);\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [placeholderThread.id]: placeholderThread,\n };\n });\n }, [placeholderThread]);\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 !== placeholderThread.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 [\n currentThreadId,\n client.beta.projects,\n client.beta.threads,\n placeholderThread.id,\n ],\n );\n\n const generateThreadName = useCallback(\n async (threadId?: string) => {\n threadId ??= currentThreadId;\n if (threadId === placeholderThread.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, placeholderThread.id],\n );\n\n const switchCurrentThread = useCallback(\n async (threadId: string, fetch = true) => {\n if (threadId === placeholderThread.id) {\n console.warn(\"Switching to placeholder thread, may be a bug.\");\n return;\n }\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[placeholderThread.id],\n id: threadId,\n },\n };\n return updatedThreadMap;\n });\n\n if (fetch) {\n await fetchThread(threadId);\n }\n },\n [fetchThread, placeholderThread],\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 const currentGenerationStage =\n currentThread?.generationStage ?? GenerationStage.IDLE;\n if (isIdleStage(currentGenerationStage as GenerationStage)) {\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, currentThread?.generationStage],\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 contextKey?: 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 onCallUnregisteredTool,\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 contextKey,\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 const wasPlaceholderThread =\n currentThreadId === PLACEHOLDER_THREAD.id;\n await switchCurrentThread(chunk.responseMessageDto.threadId, false);\n\n // If we're switching from placeholder to a real thread\n // this means a new thread was created, so refetch the threads list\n if (wasPlaceholderThread) {\n await refetchThreadsList(\n chunk.responseMessageDto.threadId,\n contextKey,\n );\n }\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 currentThreadId,\n onCallUnregisteredTool,\n refetchThreadsList,\n switchCurrentThread,\n toolRegistry,\n updateThreadMessage,\n updateThreadStatus,\n ],\n );\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 content?: TamboAI.Beta.Threads.ChatCompletionContentPart[];\n } = {},\n ): Promise<TamboThreadMessage> => {\n setIgnoreResponse(false);\n const {\n threadId = currentThreadId ?? placeholderThread.id,\n streamResponse = streaming,\n forceToolChoice,\n contextKey,\n additionalContext,\n content,\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 // Use provided content or build simple text message\n const messageContent = content ?? [\n { type: \"text\" as const, text: message },\n ];\n\n addThreadMessage(\n {\n content: messageContent as any,\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: messageContent as any,\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 ...(threadId === placeholderThread.id &&\n initialMessages.length > 0 && {\n initialMessages: initialMessages.map((msg) => ({\n content: msg.content,\n role: msg.role,\n additionalContext: msg.additionalContext,\n })),\n }),\n };\n\n if (streamResponse) {\n let advanceStreamResponse: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>;\n try {\n advanceStreamResponse = await advanceStream(\n client,\n params,\n threadId === placeholderThread.id ? undefined : threadId,\n );\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n try {\n return await handleAdvanceStream(\n advanceStreamResponse,\n params,\n threadId,\n contextKey,\n );\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n }\n\n let advanceResponse: TamboAI.Beta.Threads.ThreadAdvanceResponse;\n try {\n advanceResponse = await (threadId === placeholderThread.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceByID(threadId, params));\n } catch (error) {\n updateThreadStatus(threadId, GenerationStage.ERROR);\n throw error;\n }\n\n //handle tool calls\n try {\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 onCallUnregisteredTool,\n );\n\n const contentParts = convertToolResponse(toolCallResponse);\n\n const toolCallResponseParams: TamboAI.Beta.Threads.ThreadAdvanceParams =\n {\n ...params,\n messageToAppend: {\n ...params.messageToAppend,\n content: contentParts,\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: contentParts,\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 } catch (error) {\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.ERROR,\n );\n throw error;\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n const wasPlaceholderThread = currentThreadId === PLACEHOLDER_THREAD.id;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n\n // If we're switching from placeholder to a real thread\n // this means a new thread was created, so refetch the threads list\n if (wasPlaceholderThread) {\n await refetchThreadsList(\n advanceResponse.responseMessageDto.threadId,\n contextKey,\n );\n }\n updateThreadStatus(\n advanceResponse.responseMessageDto.threadId,\n GenerationStage.COMPLETE,\n );\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThreadId,\n switchCurrentThread,\n addThreadMessage,\n client,\n updateThreadMessage,\n updateThreadStatus,\n handleAdvanceStream,\n streaming,\n getAdditionalContext,\n placeholderThread.id,\n initialMessages,\n onCallUnregisteredTool,\n refetchThreadsList,\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 streaming,\n cancel,\n sendThreadMessage,\n }}\n >\n <TamboGenerationStageProvider\n generationStage={currentGenerationStage}\n statusMessage={currentStatusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * The useTamboGenerationStage hook provides access to the generation stage context\n * to the descendants of the TamboThreadProvider.\n * @returns The generation stage context\n */\nexport const useTamboGenerationStage = (): TamboGenerationStageContextProps => {\n const generationStageContext = useContext(TamboGenerationStageContext);\n\n if (generationStageContext === undefined) {\n throw new Error(\n \"useTamboGenerationStage must be used within a TamboThreadProvider\",\n );\n }\n\n return generationStageContext;\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 = (): CombinedTamboThreadContextProps => {\n const threadContext = useContext(TamboThreadContext);\n const generationStageContext = useContext(TamboGenerationStageContext);\n\n if (threadContext === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n\n if (generationStageContext === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n\n return {\n ...threadContext,\n ...generationStageContext,\n };\n};\n\nfunction convertToolResponse(toolCallResponse: {\n result: unknown;\n error?: string;\n tamboTool?: TamboTool;\n}): TamboAI.Beta.Threads.ChatCompletionContentPart[] {\n // If the tool call errored, surface that as text so the model reliably sees the error\n if (toolCallResponse.error) {\n return [{ type: \"text\", text: toText(toolCallResponse.result) }];\n }\n\n // Use custom transform when available\n if (toolCallResponse.tamboTool?.transformToContent) {\n return toolCallResponse.tamboTool.transformToContent(\n // result shape is user-defined; let the transform decide how to handle it\n toolCallResponse.result as any,\n );\n }\n\n // Default fallback to stringified text\n return [{ type: \"text\", text: toText(toolCallResponse.result) }];\n}\n"]}
@@ -15,6 +15,7 @@ export declare function serializeRegistry(mockRegistry: TamboComponent[]): {
15
15
  parameters: any;
16
16
  name: string;
17
17
  description: string;
18
+ transformToContent?: ((result: any) => import("@tambo-ai/typescript-sdk/resources/beta").ChatCompletionContentPart[]) | undefined;
18
19
  }[] | undefined;
19
20
  name: string;
20
21
  description: string;