@tambo-ai/react 0.19.0 → 0.19.2

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 (173) hide show
  1. package/dist/hooks/react-query-hooks.d.ts +8 -0
  2. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  3. package/dist/hooks/react-query-hooks.js +8 -0
  4. package/dist/hooks/react-query-hooks.js.map +1 -1
  5. package/dist/hooks/use-component-state.d.ts +0 -3
  6. package/dist/hooks/use-component-state.d.ts.map +1 -1
  7. package/dist/hooks/use-component-state.js +8 -26
  8. package/dist/hooks/use-component-state.js.map +1 -1
  9. package/dist/hooks/use-current-message.d.ts +27 -7
  10. package/dist/hooks/use-current-message.d.ts.map +1 -1
  11. package/dist/hooks/use-current-message.js +27 -7
  12. package/dist/hooks/use-current-message.js.map +1 -1
  13. package/dist/hooks/use-streaming-props.d.ts +0 -2
  14. package/dist/hooks/use-streaming-props.d.ts.map +1 -1
  15. package/dist/hooks/use-streaming-props.js +2 -3
  16. package/dist/hooks/use-streaming-props.js.map +1 -1
  17. package/dist/hooks/use-suggestions.d.ts +0 -1
  18. package/dist/hooks/use-suggestions.d.ts.map +1 -1
  19. package/dist/hooks/use-suggestions.js +0 -1
  20. package/dist/hooks/use-suggestions.js.map +1 -1
  21. package/dist/hooks/use-tambo-threads.d.ts +35 -5
  22. package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
  23. package/dist/hooks/use-tambo-threads.js +9 -1
  24. package/dist/hooks/use-tambo-threads.js.map +1 -1
  25. package/dist/hooks/use-thread-input.d.ts +0 -1
  26. package/dist/hooks/use-thread-input.d.ts.map +1 -1
  27. package/dist/hooks/use-thread-input.js +0 -1
  28. package/dist/hooks/use-thread-input.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +9 -2
  32. package/dist/index.js.map +1 -1
  33. package/dist/model/component-metadata.d.ts +6 -3
  34. package/dist/model/component-metadata.d.ts.map +1 -1
  35. package/dist/model/component-metadata.js.map +1 -1
  36. package/dist/model/generate-component-response.d.ts +9 -2
  37. package/dist/model/generate-component-response.d.ts.map +1 -1
  38. package/dist/model/generate-component-response.js +5 -0
  39. package/dist/model/generate-component-response.js.map +1 -1
  40. package/dist/model/tambo-thread.d.ts +4 -2
  41. package/dist/model/tambo-thread.d.ts.map +1 -1
  42. package/dist/model/tambo-thread.js.map +1 -1
  43. package/dist/model/validate-input.d.ts +5 -0
  44. package/dist/model/validate-input.d.ts.map +1 -1
  45. package/dist/model/validate-input.js +5 -1
  46. package/dist/model/validate-input.js.map +1 -1
  47. package/dist/providers/tambo-client-provider.d.ts +31 -0
  48. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  49. package/dist/providers/tambo-client-provider.js +21 -0
  50. package/dist/providers/tambo-client-provider.js.map +1 -1
  51. package/dist/providers/tambo-component-provider.d.ts +12 -0
  52. package/dist/providers/tambo-component-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-component-provider.js +24 -0
  54. package/dist/providers/tambo-component-provider.js.map +1 -1
  55. package/dist/providers/tambo-provider.d.ts +18 -1
  56. package/dist/providers/tambo-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-provider.js +25 -2
  58. package/dist/providers/tambo-provider.js.map +1 -1
  59. package/dist/providers/tambo-registry-provider.d.ts +14 -1
  60. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  61. package/dist/providers/tambo-registry-provider.js +25 -0
  62. package/dist/providers/tambo-registry-provider.js.map +1 -1
  63. package/dist/providers/tambo-thread-provider.d.ts +25 -2
  64. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  65. package/dist/providers/tambo-thread-provider.js +32 -26
  66. package/dist/providers/tambo-thread-provider.js.map +1 -1
  67. package/dist/util/generate-component.d.ts +5 -1
  68. package/dist/util/generate-component.d.ts.map +1 -1
  69. package/dist/util/generate-component.js +5 -1
  70. package/dist/util/generate-component.js.map +1 -1
  71. package/dist/util/query-utils.d.ts +16 -0
  72. package/dist/util/query-utils.d.ts.map +1 -1
  73. package/dist/util/query-utils.js +16 -0
  74. package/dist/util/query-utils.js.map +1 -1
  75. package/dist/util/registry.d.ts +27 -1
  76. package/dist/util/registry.d.ts.map +1 -1
  77. package/dist/util/registry.js +29 -4
  78. package/dist/util/registry.js.map +1 -1
  79. package/dist/util/tool-caller.d.ts +6 -0
  80. package/dist/util/tool-caller.d.ts.map +1 -1
  81. package/dist/util/tool-caller.js +6 -0
  82. package/dist/util/tool-caller.js.map +1 -1
  83. package/esm/hooks/react-query-hooks.d.ts +8 -0
  84. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  85. package/esm/hooks/react-query-hooks.js +8 -0
  86. package/esm/hooks/react-query-hooks.js.map +1 -1
  87. package/esm/hooks/use-component-state.d.ts +0 -3
  88. package/esm/hooks/use-component-state.d.ts.map +1 -1
  89. package/esm/hooks/use-component-state.js +2 -23
  90. package/esm/hooks/use-component-state.js.map +1 -1
  91. package/esm/hooks/use-current-message.d.ts +27 -7
  92. package/esm/hooks/use-current-message.d.ts.map +1 -1
  93. package/esm/hooks/use-current-message.js +27 -7
  94. package/esm/hooks/use-current-message.js.map +1 -1
  95. package/esm/hooks/use-streaming-props.d.ts +0 -2
  96. package/esm/hooks/use-streaming-props.d.ts.map +1 -1
  97. package/esm/hooks/use-streaming-props.js +2 -3
  98. package/esm/hooks/use-streaming-props.js.map +1 -1
  99. package/esm/hooks/use-suggestions.d.ts +0 -1
  100. package/esm/hooks/use-suggestions.d.ts.map +1 -1
  101. package/esm/hooks/use-suggestions.js +0 -1
  102. package/esm/hooks/use-suggestions.js.map +1 -1
  103. package/esm/hooks/use-tambo-threads.d.ts +35 -5
  104. package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
  105. package/esm/hooks/use-tambo-threads.js +9 -1
  106. package/esm/hooks/use-tambo-threads.js.map +1 -1
  107. package/esm/hooks/use-thread-input.d.ts +0 -1
  108. package/esm/hooks/use-thread-input.d.ts.map +1 -1
  109. package/esm/hooks/use-thread-input.js +0 -1
  110. package/esm/hooks/use-thread-input.js.map +1 -1
  111. package/esm/index.d.ts +1 -1
  112. package/esm/index.d.ts.map +1 -1
  113. package/esm/index.js +1 -1
  114. package/esm/index.js.map +1 -1
  115. package/esm/model/component-metadata.d.ts +6 -3
  116. package/esm/model/component-metadata.d.ts.map +1 -1
  117. package/esm/model/component-metadata.js.map +1 -1
  118. package/esm/model/generate-component-response.d.ts +9 -2
  119. package/esm/model/generate-component-response.d.ts.map +1 -1
  120. package/esm/model/generate-component-response.js +5 -0
  121. package/esm/model/generate-component-response.js.map +1 -1
  122. package/esm/model/tambo-thread.d.ts +4 -2
  123. package/esm/model/tambo-thread.d.ts.map +1 -1
  124. package/esm/model/tambo-thread.js.map +1 -1
  125. package/esm/model/validate-input.d.ts +5 -0
  126. package/esm/model/validate-input.d.ts.map +1 -1
  127. package/esm/model/validate-input.js +5 -1
  128. package/esm/model/validate-input.js.map +1 -1
  129. package/esm/providers/tambo-client-provider.d.ts +31 -0
  130. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  131. package/esm/providers/tambo-client-provider.js +21 -0
  132. package/esm/providers/tambo-client-provider.js.map +1 -1
  133. package/esm/providers/tambo-component-provider.d.ts +12 -0
  134. package/esm/providers/tambo-component-provider.d.ts.map +1 -1
  135. package/esm/providers/tambo-component-provider.js +24 -0
  136. package/esm/providers/tambo-component-provider.js.map +1 -1
  137. package/esm/providers/tambo-provider.d.ts +18 -1
  138. package/esm/providers/tambo-provider.d.ts.map +1 -1
  139. package/esm/providers/tambo-provider.js +25 -2
  140. package/esm/providers/tambo-provider.js.map +1 -1
  141. package/esm/providers/tambo-registry-provider.d.ts +14 -1
  142. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  143. package/esm/providers/tambo-registry-provider.js +25 -0
  144. package/esm/providers/tambo-registry-provider.js.map +1 -1
  145. package/esm/providers/tambo-thread-provider.d.ts +25 -2
  146. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  147. package/esm/providers/tambo-thread-provider.js +32 -26
  148. package/esm/providers/tambo-thread-provider.js.map +1 -1
  149. package/esm/util/generate-component.d.ts +5 -1
  150. package/esm/util/generate-component.d.ts.map +1 -1
  151. package/esm/util/generate-component.js +5 -1
  152. package/esm/util/generate-component.js.map +1 -1
  153. package/esm/util/query-utils.d.ts +16 -0
  154. package/esm/util/query-utils.d.ts.map +1 -1
  155. package/esm/util/query-utils.js +16 -0
  156. package/esm/util/query-utils.js.map +1 -1
  157. package/esm/util/registry.d.ts +27 -1
  158. package/esm/util/registry.d.ts.map +1 -1
  159. package/esm/util/registry.js +28 -2
  160. package/esm/util/registry.js.map +1 -1
  161. package/esm/util/tool-caller.d.ts +6 -0
  162. package/esm/util/tool-caller.d.ts.map +1 -1
  163. package/esm/util/tool-caller.js +6 -0
  164. package/esm/util/tool-caller.js.map +1 -1
  165. package/package.json +4 -2
  166. package/dist/util/messages.d.ts +0 -3
  167. package/dist/util/messages.d.ts.map +0 -1
  168. package/dist/util/messages.js +0 -12
  169. package/dist/util/messages.js.map +0 -1
  170. package/esm/util/messages.d.ts +0 -3
  171. package/esm/util/messages.d.ts.map +0 -1
  172. package/esm/util/messages.js +0 -9
  173. package/esm/util/messages.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,mEAMiC;AACjC,yEAIoC;AACpC,uEAGmC;AACnC,mEAIiC;AAEjC,mFAAmF;AAE5E,MAAM,aAAa,GAEtB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE;IAC9D,OAAO,CACL,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW;QAExB,8BAAC,+CAAqB,IAAC,UAAU,EAAE,UAAU;YAC3C,8BAAC,2CAAmB;gBAClB,8BAAC,iDAAsB;oBACrB,8BAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,aAAa,iBAkBxB;AAKW,QAAA,YAAY,GAAG,IAAA,qBAAa,EACvC,EAAuB,CACxB,CAAC;AAEF,oHAAoH;AACpH,MAAM,sBAAsB,GAAgC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC3E,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,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAE9C,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEK,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 {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/** TamboProvider gives full access to the TamboAI client and component registry */\n\nexport const TamboProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>\n> = ({ children, tamboUrl, apiKey, components, environment }) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components}>\n <TamboThreadProvider>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\ntype TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/** TamboCompositeProvider is a provider that combines the TamboClient, TamboThread, and TamboComponent providers */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\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;AAC5E,mEAMiC;AACjC,yEAIoC;AACpC,uEAGmC;AACnC,mEAIiC;AAEjC;;;;;;;;;;GAUG;AACI,MAAM,aAAa,GAEtB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE;IAC9D,OAAO,CACL,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW;QAExB,8BAAC,+CAAqB,IAAC,UAAU,EAAE,UAAU;YAC3C,8BAAC,2CAAmB;gBAClB,8BAAC,iDAAsB;oBACrB,8BAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,aAAa,iBAkBxB;AAKW,QAAA,YAAY,GAAG,IAAA,qBAAa,EACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAgC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC3E,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,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAE9C,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;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 {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>\n> = ({ children, tamboUrl, apiKey, components, environment }) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components}>\n <TamboThreadProvider>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\ntype TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -10,9 +10,22 @@ export interface TamboRegistryContext {
10
10
  addToolAssociation: (componentName: string, tool: TamboTool) => void;
11
11
  }
12
12
  export interface TamboRegistryProviderProps {
13
- /** The default components to register */
13
+ /** The components to register */
14
14
  components?: TamboComponent[];
15
15
  }
16
+ /**
17
+ * The TamboRegistryProvider is a React provider that provides a component
18
+ * registry to the descendants of the provider.
19
+ * @param props - The props for the TamboRegistryProvider
20
+ * @param props.children - The children to wrap
21
+ * @param props.components - The components to register
22
+ * @returns The TamboRegistryProvider component
23
+ */
16
24
  export declare const TamboRegistryProvider: React.FC<PropsWithChildren<TamboRegistryProviderProps>>;
25
+ /**
26
+ * The useTamboRegistry hook provides access to the component registry
27
+ * to the descendants of the TamboRegistryProvider.
28
+ * @returns The component registry
29
+ */
17
30
  export declare const useTamboRegistry: () => TamboRegistryContext;
18
31
  //# sourceMappingURL=tambo-registry-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACxC,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACtE;AAYD,MAAM,WAAW,0BAA0B;IACzC,yCAAyC;IACzC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CAqI9C,CAAC;AAEF,eAAO,MAAM,gBAAgB,4BAE5B,CAAC"}
1
+ {"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACxC,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACtE;AAwBD,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CAqI9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAE5B,CAAC"}
@@ -44,11 +44,31 @@ const TamboRegistryContext = (0, react_1.createContext)({
44
44
  componentList: {},
45
45
  toolRegistry: {},
46
46
  componentToolAssociations: {},
47
+ /**
48
+ *
49
+ */
47
50
  registerComponent: () => { },
51
+ /**
52
+ *
53
+ */
48
54
  registerTool: () => { },
55
+ /**
56
+ *
57
+ */
49
58
  registerTools: () => { },
59
+ /**
60
+ *
61
+ */
50
62
  addToolAssociation: () => { },
51
63
  });
64
+ /**
65
+ * The TamboRegistryProvider is a React provider that provides a component
66
+ * registry to the descendants of the provider.
67
+ * @param props - The props for the TamboRegistryProvider
68
+ * @param props.children - The children to wrap
69
+ * @param props.components - The components to register
70
+ * @returns The TamboRegistryProvider component
71
+ */
52
72
  const TamboRegistryProvider = ({ children, components: userComponents }) => {
53
73
  const [componentList, setComponentList] = (0, react_1.useState)({});
54
74
  const [toolRegistry, setToolRegistry] = (0, react_1.useState)({});
@@ -139,6 +159,11 @@ const TamboRegistryProvider = ({ children, components: userComponents }) => {
139
159
  return (react_1.default.createElement(TamboRegistryContext.Provider, { value: value }, children));
140
160
  };
141
161
  exports.TamboRegistryProvider = TamboRegistryProvider;
162
+ /**
163
+ * The useTamboRegistry hook provides access to the component registry
164
+ * to the descendants of the TamboRegistryProvider.
165
+ * @returns The component registry
166
+ */
142
167
  const useTamboRegistry = () => {
143
168
  return (0, react_1.useContext)(TamboRegistryContext);
144
169
  };
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAOe;AACf,4EAAiD;AAiBjD,MAAM,oBAAoB,GAAG,IAAA,qBAAa,EAAuB;IAC/D,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,yBAAyB,EAAE,EAAE;IAC7B,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,aAAa,EAAE,GAAG,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EAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n registerComponent: () => {},\n registerTool: () => {},\n registerTools: () => {},\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The default components to register */\n components?: TamboComponent[];\n}\n\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({ children, components: userComponents }) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Convert propsSchema to JSON Schema if it exists\n let props = propsDefinition;\n if (propsSchema) {\n try {\n props = zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\n"]}
1
+ {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;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iB,EAAE,cAAc,CAAC,CAAC,CAAC;IAExC,MAAM,KAAK,GAAG;QACZ,aAAa;QACb,YAAY;QACZ,yBAAyB;QACzB,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,CAAC;IAEF,OAAO,CACL,8BAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACxC,QAAQ,CACqB,CACjC,CAAC;AACJ,CAAC,CAAC;AAtIW,QAAA,qBAAqB,yBAsIhC;AAEF;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,IAAA,kBAAU,EAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({ children, components: userComponents }) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Convert propsSchema to JSON Schema if it exists\n let props = propsDefinition;\n if (propsSchema) {\n try {\n props = zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\n"]}
@@ -3,24 +3,35 @@ import React, { PropsWithChildren } from "react";
3
3
  import { GenerationStage, TamboThreadMessage } from "../model/generate-component-response";
4
4
  import { TamboThread } from "../model/tambo-thread";
5
5
  export interface TamboThreadContextProps {
6
+ /** The current thread */
6
7
  thread: TamboThread;
8
+ /** Switch to a different thread */
7
9
  switchCurrentThread: (threadId: string, fetch?: boolean) => void;
10
+ /** Start a new thread */
8
11
  startNewThread: () => void;
12
+ /** Add a message to the current thread */
9
13
  addThreadMessage: (message: TamboThreadMessage, sendToServer: boolean) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;
14
+ /** Update a message in the current thread */
10
15
  updateThreadMessage: (id: string, message: TamboThreadMessage, sendToServer: boolean) => Promise<void>;
11
- setLastThreadStatus: (status: GenerationStage) => void;
16
+ /** The input value of the current thread */
12
17
  inputValue: string;
18
+ /** Set the input value of the current thread */
13
19
  setInputValue: (value: string) => void;
20
+ /** Send a message to the current thread */
14
21
  sendThreadMessage: (message: string, options?: {
15
22
  threadId?: string;
16
23
  streamResponse?: boolean;
17
24
  contextKey?: string;
18
25
  }) => Promise<TamboThreadMessage>;
26
+ /** The generation stage of the current thread - updated as the thread progresses */
19
27
  generationStage: GenerationStage;
28
+ /** The generation status message of the current thread - updated as the thread progresses */
20
29
  generationStatusMessage: string;
30
+ /** Whether the thread is idle */
21
31
  isIdle: boolean;
22
32
  }
23
- /** This is a stub entry for when the thread is not yet created, the first time
33
+ /**
34
+ * This is a stub entry for when the thread is not yet created, the first time
24
35
  * the user sends a message
25
36
  *
26
37
  * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,
@@ -28,6 +39,18 @@ export interface TamboThreadContextProps {
28
39
  */
29
40
  export declare const PLACEHOLDER_THREAD: TamboThread;
30
41
  export declare const TamboThreadContext: React.Context<TamboThreadContextProps>;
42
+ /**
43
+ * The TamboThreadProvider is a React provider that provides a thread context
44
+ * to the descendants of the provider.
45
+ * @param props - The props for the TamboThreadProvider
46
+ * @param props.children - The children to wrap
47
+ * @returns The TamboThreadProvider component
48
+ */
31
49
  export declare const TamboThreadProvider: React.FC<PropsWithChildren>;
50
+ /**
51
+ * The useTamboThread hook provides access to the current thread context
52
+ * to the descendants of the TamboThreadProvider.
53
+ * @returns All state and actions for the current thread
54
+ */
32
55
  export declare const useTamboThread: () => TamboThreadContextProps;
33
56
  //# sourceMappingURL=tambo-thread-provider.d.ts.map
@@ -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,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,eAAe,EAEf,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,E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,MAAM,kBAAkB,wCA0C7B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4d3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC"}
@@ -43,7 +43,8 @@ const registry_1 = require("../util/registry");
43
43
  const tool_caller_1 = require("../util/tool-caller");
44
44
  const tambo_client_provider_1 = require("./tambo-client-provider");
45
45
  const tambo_registry_provider_1 = require("./tambo-registry-provider");
46
- /** This is a stub entry for when the thread is not yet created, the first time
46
+ /**
47
+ * This is a stub entry for when the thread is not yet created, the first time
47
48
  * the user sends a message
48
49
  *
49
50
  * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,
@@ -59,25 +60,40 @@ exports.PLACEHOLDER_THREAD = {
59
60
  };
60
61
  exports.TamboThreadContext = (0, react_1.createContext)({
61
62
  thread: exports.PLACEHOLDER_THREAD,
63
+ /**
64
+ *
65
+ */
62
66
  switchCurrentThread: () => {
63
67
  throw new Error("switchCurrentThread not implemented");
64
68
  },
69
+ /**
70
+ *
71
+ */
65
72
  startNewThread: () => {
66
73
  throw new Error("startNewThread not implemented");
67
74
  },
75
+ /**
76
+ *
77
+ */
68
78
  addThreadMessage: () => {
69
79
  throw new Error("updateThreadMessageHistory not implemented");
70
80
  },
71
- setLastThreadStatus: () => {
72
- throw new Error("setLastThreadStatus not implemented");
73
- },
74
81
  inputValue: "",
82
+ /**
83
+ *
84
+ */
75
85
  setInputValue: () => {
76
86
  throw new Error("setInputValue not implemented");
77
87
  },
88
+ /**
89
+ *
90
+ */
78
91
  updateThreadMessage: () => {
79
92
  throw new Error("updateThreadMessage not implemented");
80
93
  },
94
+ /**
95
+ *
96
+ */
81
97
  sendThreadMessage: () => {
82
98
  throw new Error("advance not implemented");
83
99
  },
@@ -85,6 +101,13 @@ exports.TamboThreadContext = (0, react_1.createContext)({
85
101
  generationStatusMessage: "",
86
102
  isIdle: true,
87
103
  });
104
+ /**
105
+ * The TamboThreadProvider is a React provider that provides a thread context
106
+ * to the descendants of the provider.
107
+ * @param props - The props for the TamboThreadProvider
108
+ * @param props.children - The children to wrap
109
+ * @returns The TamboThreadProvider component
110
+ */
88
111
  const TamboThreadProvider = ({ children, }) => {
89
112
  const [threadMap, setThreadMap] = (0, react_1.useState)({
90
113
  [exports.PLACEHOLDER_THREAD.id]: exports.PLACEHOLDER_THREAD,
@@ -245,26 +268,6 @@ const TamboThreadProvider = ({ children, }) => {
245
268
  await fetchThread(threadId);
246
269
  }
247
270
  }, [fetchThread, threadMap]);
248
- const setLastThreadStatus = (status) => {
249
- setThreadMap((prevMap) => {
250
- if (!currentThreadId) {
251
- return prevMap;
252
- }
253
- const headMessages = prevMap[currentThreadId].messages.slice(0, -1);
254
- const lastMessage = prevMap[currentThreadId].messages[prevMap[currentThreadId].messages.length - 1];
255
- const updatedLastMessage = {
256
- ...lastMessage,
257
- status,
258
- };
259
- return {
260
- ...prevMap,
261
- [currentThreadId]: {
262
- ...prevMap[currentThreadId],
263
- messages: [...headMessages, updatedLastMessage],
264
- },
265
- };
266
- });
267
- };
268
271
  const updateThreadStatus = (0, react_1.useCallback)((stage, statusMessage) => {
269
272
  setThreadMap((prevMap) => {
270
273
  return {
@@ -422,7 +425,6 @@ const TamboThreadProvider = ({ children, }) => {
422
425
  componentToolAssociations,
423
426
  currentThread,
424
427
  switchCurrentThread,
425
- startNewThread,
426
428
  addThreadMessage,
427
429
  client,
428
430
  updateThreadStatus,
@@ -434,7 +436,6 @@ const TamboThreadProvider = ({ children, }) => {
434
436
  startNewThread,
435
437
  addThreadMessage,
436
438
  updateThreadMessage,
437
- setLastThreadStatus,
438
439
  inputValue,
439
440
  setInputValue,
440
441
  sendThreadMessage,
@@ -446,6 +447,11 @@ const TamboThreadProvider = ({ children, }) => {
446
447
  } }, children));
447
448
  };
448
449
  exports.TamboThreadProvider = TamboThreadProvider;
450
+ /**
451
+ * The useTamboThread hook provides access to the current thread context
452
+ * to the descendants of the TamboThreadProvider.
453
+ * @returns All state and actions for the current thread
454
+ */
449
455
  const useTamboThread = () => {
450
456
  const context = (0, react_1.useContext)(exports.TamboThreadContext);
451
457
  if (context === undefined) {
@@ -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;AAClE,+CAQe;AACf,sFAI8C;AAE9C,mEAAwE;AACxE,+CAA4E;AAC5E,qDAAqD;AACrD,mEAAyD;AACzD,uEAA6D;AA+B7D;;;;;GAKG;AACU,QAAA,kBAAkB,GAAgB;IAC7C,EAAE,EAAE,aAAa;IACjB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,EAAE;CACb,CAAC;AAEW,QAAA,kBAAkB,GAAG,IAAA,qBAAa,EAA0B;IACvE,MAAM,EAAE,0BAAkB;IAC1B,mBAAmB,EAAE,GAAG,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,gBAAgB,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,mBAAmB,EAAE,GAAG,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IACD,mBAAmB,EAAE,GAAG,EAAE;QACxB,MAAM,IAAI,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BAAkB;QAClB,mBAAmB;KACpB,CACF,CAAC;IAEF,OAAO,CACL,8BAAC,0BAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,MAAM,EAAE,aAAa;YACrB,mBAAmB;YACnB,cAAc;YACd,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,UAAU;YACV,aAAa;YACb,iBAAiB;YACjB,eAAe,EAAE,CAAC,aAAa,EAAE,eAAe;gBAC9C,6CAAe,CAAC,IAAI,CAAoB;YAC1C,uBAAuB,EAAE,aAAa,EAAE,aAAa,IAAI,EAAE;YAC3D,MAAM,EAAE,IAAA,yCAAW,EACjB,CAAC,aAAa,EAAE,eAAe;gBAC7B,6CAAe,CAAC,IAAI,CAAoB,CAC3C;SACF,IAEA,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AAtfW,QAAA,mBAAmB,uBAsf9B;AAEK,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,0BAAkB,CAAC,CAAC;IAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["\"use client\";\nimport TamboAI, { advanceStream } from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\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 { getAvailableComponents, getClientContext } from \"../util/registry\";\nimport { handleToolCall } from \"../util/tool-caller\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\nexport interface TamboThreadContextProps {\n thread: TamboThread;\n switchCurrentThread: (threadId: string, fetch?: boolean) => void;\n startNewThread: () => void;\n addThreadMessage: (\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;\n updateThreadMessage: (\n id: string,\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<void>;\n setLastThreadStatus: (status: GenerationStage) => void;\n inputValue: string;\n setInputValue: (value: string) => void;\n sendThreadMessage: (\n message: string,\n options?: {\n threadId?: string;\n streamResponse?: boolean;\n contextKey?: string;\n },\n ) => Promise<TamboThreadMessage>;\n generationStage: GenerationStage;\n generationStatusMessage: string;\n isIdle: boolean;\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 switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented\");\n },\n addThreadMessage: () => {\n throw new Error(\"updateThreadMessageHistory not implemented\");\n },\n setLastThreadStatus: () => {\n throw new Error(\"setLastThreadStatus not implemented\");\n },\n inputValue: \"\",\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n sendThreadMessage: () => {\n throw new Error(\"advance not implemented\");\n },\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n});\n\nexport const TamboThreadProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [threadMap, setThreadMap] = useState<Record<string, TamboThread>>({\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n });\n const client = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n const [inputValue, setInputValue] = useState(\"\");\n\n const [currentThreadId, setCurrentThreadId] = useState<string>(\n PLACEHOLDER_THREAD.id,\n );\n const currentThread: TamboThread | undefined = threadMap[currentThreadId];\n\n // Use existing messages from the current thread to avoid re-generating any components\n const currentMessageCache = useMemo(() => {\n const messageCache = new Map<string, TamboThreadMessage>();\n if (currentThread) {\n for (const message of currentThread.messages) {\n messageCache.set(message.id, message);\n }\n }\n return messageCache;\n }, [currentThread]);\n\n 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 ...prevMap,\n [threadId]: threadWithRenderedComponents,\n }));\n },\n [client.beta.threads, componentList, currentMessageCache],\n );\n\n useEffect(() => {\n if (\n currentThreadId &&\n currentThreadId !== PLACEHOLDER_THREAD.id &&\n !threadMap[currentThreadId]\n ) {\n fetchThread(currentThreadId);\n }\n }, [currentThreadId, fetchThread, threadMap]);\n\n const addThreadMessage = useCallback(\n async (\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n if (!currentThread) {\n console.warn(\"Cannot add messages if we do not have a current thread\");\n return [];\n }\n const chatMessage: TamboThreadMessage & {\n additionalContext?: string;\n } = {\n ...message,\n additionalContext:\n message.role === \"user\" ? getClientContext() : undefined,\n createdAt,\n };\n const threadId = message.threadId;\n // 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 return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n messages: [...prevMessages, chatMessage],\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(currentThreadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n const updatedMessageHistory = [...currentThread.messages, chatMessage];\n\n return updatedMessageHistory;\n },\n [client.beta.threads.messages, currentThread, currentThreadId],\n );\n\n const updateThreadMessage = useCallback(\n async (\n id: string,\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n const chatMessage: TamboThreadMessage = {\n ...message,\n createdAt,\n };\n\n setThreadMap((prevMap) => {\n if (!message.threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n return chatMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(currentThreadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n },\n [client.beta.threads.messages, currentThreadId],\n );\n\n const deleteThreadMessage = useCallback(\n (messageId: string) => {\n if (!currentThread) return;\n\n setThreadMap((prevMap) => ({\n ...prevMap,\n [currentThread.id]: {\n ...prevMap[currentThread.id],\n messages: prevMap[currentThread.id].messages.filter(\n (msg) => msg.id !== messageId,\n ),\n },\n }));\n },\n [currentThread],\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 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 if (!threadMap[threadId]) {\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[PLACEHOLDER_THREAD.id],\n id: threadId,\n },\n };\n });\n }\n if (fetch) {\n await fetchThread(threadId);\n }\n },\n [fetchThread, threadMap],\n );\n\n const setLastThreadStatus = (status: GenerationStage) => {\n setThreadMap((prevMap) => {\n if (!currentThreadId) {\n return prevMap;\n }\n const headMessages = prevMap[currentThreadId].messages.slice(0, -1);\n const lastMessage =\n prevMap[currentThreadId].messages[\n prevMap[currentThreadId].messages.length - 1\n ];\n const updatedLastMessage = {\n ...lastMessage,\n status,\n };\n return {\n ...prevMap,\n [currentThreadId]: {\n ...prevMap[currentThreadId],\n messages: [...headMessages, updatedLastMessage],\n },\n };\n });\n };\n\n const updateThreadStatus = useCallback(\n (stage: GenerationStage, statusMessage?: string) => {\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [currentThreadId]: {\n ...prevMap[currentThreadId],\n generationStage: stage,\n statusMessage: statusMessage,\n },\n };\n });\n },\n [currentThreadId],\n );\n\n const handleAdvanceStream = useCallback(\n async (\n stream: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>,\n params: TamboAI.Beta.Threads.ThreadAdvanceParams,\n messageIdToRemove?: string,\n ): Promise<TamboThreadMessage> => {\n let finalMessage: TamboThreadMessage | undefined;\n let hasSetThreadId = false;\n let isFirstChunk = true;\n updateThreadStatus(GenerationStage.STREAMING_RESPONSE);\n\n for await (const chunk of stream) {\n if (isFirstChunk && messageIdToRemove) {\n deleteThreadMessage(messageIdToRemove);\n }\n isFirstChunk = false;\n\n if (chunk.responseMessageDto.toolCallRequest) {\n updateThreadStatus(GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n chunk.responseMessageDto,\n toolRegistry,\n );\n const toolCallResponseString =\n typeof toolCallResponse === \"string\"\n ? toolCallResponse\n : JSON.stringify(toolCallResponse);\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 },\n };\n updateThreadStatus(GenerationStage.STREAMING_RESPONSE);\n const toolCallResponseStream = await advanceStream(\n client,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n\n // Pass the current message's ID to be removed when the new stream starts, since we now know it is a tool call request message\n return await handleAdvanceStream(\n toolCallResponseStream,\n toolCallResponseParams,\n finalMessage?.id,\n );\n } else {\n if (\n !hasSetThreadId &&\n chunk.responseMessageDto.threadId &&\n chunk.responseMessageDto.threadId !== currentThread?.id\n ) {\n hasSetThreadId = true;\n switchCurrentThread(chunk.responseMessageDto.threadId, false);\n }\n\n if (!finalMessage) {\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n addThreadMessage(finalMessage, false);\n } else {\n const previousId = finalMessage.id;\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n updateThreadMessage(previousId, finalMessage, false);\n }\n }\n }\n\n updateThreadStatus(GenerationStage.COMPLETE);\n if (finalMessage) {\n await fetchThread(finalMessage.threadId);\n }\n return (\n finalMessage ?? {\n threadId: \"\",\n content: [{ type: \"text\", text: `Error processing stream` }],\n role: \"hydra\",\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 deleteThreadMessage,\n fetchThread,\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 contextKey?: string;\n } = {},\n ): Promise<TamboThreadMessage> => {\n const { threadId, streamResponse } = options;\n const currentThreadId = threadId ?? currentThread?.id;\n\n if (currentThreadId !== PLACEHOLDER_THREAD.id) {\n await switchCurrentThread(currentThreadId);\n }\n\n updateThreadStatus(GenerationStage.CHOOSING_COMPONENT);\n\n addThreadMessage(\n {\n content: [{ type: \"text\", text: message }],\n renderedComponent: null,\n role: \"user\",\n threadId: currentThread.id,\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n },\n false,\n );\n\n const availableComponents = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n const params: TamboAI.Beta.Threads.ThreadAdvanceParams = {\n messageToAppend: {\n content: [{ type: \"text\", text: message }],\n role: \"user\",\n },\n contextKey: options.contextKey,\n availableComponents: availableComponents,\n };\n\n if (streamResponse) {\n const advanceStreamResponse = await advanceStream(\n client,\n params,\n currentThreadId === PLACEHOLDER_THREAD.id\n ? undefined\n : currentThreadId,\n );\n return await handleAdvanceStream(advanceStreamResponse, params);\n }\n let advanceResponse = await (currentThreadId === PLACEHOLDER_THREAD.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceById(currentThreadId, params));\n\n //handle tool calls\n while (advanceResponse.responseMessageDto.toolCallRequest) {\n updateThreadStatus(GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n advanceResponse.responseMessageDto,\n toolRegistry,\n );\n const toolResponseString =\n typeof toolCallResponse === \"string\"\n ? toolCallResponse\n : JSON.stringify(toolCallResponse);\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 },\n };\n updateThreadStatus(GenerationStage.HYDRATING_COMPONENT);\n advanceResponse = await client.beta.threads.advanceById(\n advanceResponse.responseMessageDto.threadId,\n toolCallResponseParams,\n );\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n updateThreadStatus(GenerationStage.COMPLETE);\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThread,\n switchCurrentThread,\n startNewThread,\n addThreadMessage,\n client,\n updateThreadStatus,\n handleAdvanceStream,\n ],\n );\n\n return (\n <TamboThreadContext.Provider\n value={{\n thread: currentThread,\n switchCurrentThread,\n startNewThread,\n addThreadMessage,\n updateThreadMessage,\n setLastThreadStatus,\n inputValue,\n setInputValue,\n sendThreadMessage,\n generationStage: (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n generationStatusMessage: currentThread?.statusMessage ?? \"\",\n isIdle: isIdleStage(\n (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n ),\n }}\n >\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\nexport const useTamboThread = () => {\n const context = useContext(TamboThreadContext);\n if (context === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n return context;\n};\n"]}
1
+ {"version":3,"file":"tambo-thread-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,6DAAkE;AAClE,+CAQe;AACf,sFAI8C;AAE9C,mEAAwE;AACxE,+CAA4E;AAC5E,qDAAqD;AACrD,mEAAyD;AACzD,uEAA6D;AAyC7D;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAgB;IAC7C,EAAE,EAAE,aAAa;IACjB,QAAQ,EAAE,EAAE;IACZ,SAAS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AmB;KACpB,CACF,CAAC;IAEF,OAAO,CACL,8BAAC,0BAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,MAAM,EAAE,aAAa;YACrB,mBAAmB;YACnB,cAAc;YACd,gBAAgB;YAChB,mBAAmB;YACnB,UAAU;YACV,aAAa;YACb,iBAAiB;YACjB,eAAe,EAAE,CAAC,aAAa,EAAE,eAAe;gBAC9C,6CAAe,CAAC,IAAI,CAAoB;YAC1C,uBAAuB,EAAE,aAAa,EAAE,aAAa,IAAI,EAAE;YAC3D,MAAM,EAAE,IAAA,yCAAW,EACjB,CAAC,aAAa,EAAE,eAAe;gBAC7B,6CAAe,CAAC,IAAI,CAAoB,CAC3C;SACF,IAEA,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AA5dW,QAAA,mBAAmB,uBA4d9B;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,0BAAkB,CAAC,CAAC;IAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["\"use client\";\nimport TamboAI, { advanceStream } from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\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 { getAvailableComponents, getClientContext } from \"../util/registry\";\nimport { handleToolCall } from \"../util/tool-caller\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\nexport interface TamboThreadContextProps {\n /** The current thread */\n thread: TamboThread;\n /** Switch to a different thread */\n switchCurrentThread: (threadId: string, fetch?: boolean) => void;\n /** Start a new thread */\n startNewThread: () => void;\n /** Add a message to the current thread */\n addThreadMessage: (\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;\n /** Update a message in the current thread */\n updateThreadMessage: (\n id: string,\n message: TamboThreadMessage,\n sendToServer: boolean,\n ) => Promise<void>;\n /** The input value of the current thread */\n inputValue: string;\n /** Set the input value of the current thread */\n setInputValue: (value: string) => void;\n /** Send a message to the current thread */\n sendThreadMessage: (\n message: string,\n options?: {\n threadId?: string;\n streamResponse?: boolean;\n contextKey?: string;\n },\n ) => Promise<TamboThreadMessage>;\n /** The generation stage of the current thread - updated as the thread progresses */\n generationStage: GenerationStage;\n /** The generation status message of the current thread - updated as the thread progresses */\n generationStatusMessage: string;\n /** Whether the thread is idle */\n isIdle: boolean;\n}\n\n/**\n * This is a stub entry for when the thread is not yet created, the first time\n * the user sends a message\n *\n * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,\n * as this doesn't really exist on the server side.\n */\nexport const PLACEHOLDER_THREAD: TamboThread = {\n id: \"placeholder\",\n messages: [],\n createdAt: \"\",\n projectId: \"\",\n updatedAt: \"\",\n metadata: {},\n};\n\nexport const TamboThreadContext = createContext<TamboThreadContextProps>({\n thread: PLACEHOLDER_THREAD,\n /**\n *\n */\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented\");\n },\n /**\n *\n */\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented\");\n },\n /**\n *\n */\n addThreadMessage: () => {\n throw new Error(\"updateThreadMessageHistory not implemented\");\n },\n inputValue: \"\",\n /**\n *\n */\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented\");\n },\n /**\n *\n */\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented\");\n },\n /**\n *\n */\n sendThreadMessage: () => {\n throw new Error(\"advance not implemented\");\n },\n generationStage: GenerationStage.IDLE,\n generationStatusMessage: \"\",\n isIdle: true,\n});\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 * @returns The TamboThreadProvider component\n */\nexport const TamboThreadProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [threadMap, setThreadMap] = useState<Record<string, TamboThread>>({\n [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,\n });\n const client = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n const [inputValue, setInputValue] = useState(\"\");\n\n const [currentThreadId, setCurrentThreadId] = useState<string>(\n PLACEHOLDER_THREAD.id,\n );\n const currentThread: TamboThread | undefined = threadMap[currentThreadId];\n\n // Use existing messages from the current thread to avoid re-generating any components\n const currentMessageCache = useMemo(() => {\n const messageCache = new Map<string, TamboThreadMessage>();\n if (currentThread) {\n for (const message of currentThread.messages) {\n messageCache.set(message.id, message);\n }\n }\n return messageCache;\n }, [currentThread]);\n\n 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 ...prevMap,\n [threadId]: threadWithRenderedComponents,\n }));\n },\n [client.beta.threads, componentList, currentMessageCache],\n );\n\n useEffect(() => {\n if (\n currentThreadId &&\n currentThreadId !== PLACEHOLDER_THREAD.id &&\n !threadMap[currentThreadId]\n ) {\n fetchThread(currentThreadId);\n }\n }, [currentThreadId, fetchThread, threadMap]);\n\n const addThreadMessage = useCallback(\n async (\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n if (!currentThread) {\n console.warn(\"Cannot add messages if we do not have a current thread\");\n return [];\n }\n const chatMessage: TamboThreadMessage & {\n additionalContext?: string;\n } = {\n ...message,\n additionalContext:\n message.role === \"user\" ? getClientContext() : undefined,\n createdAt,\n };\n const threadId = message.threadId;\n // 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 return {\n ...prevMap,\n [threadId]: {\n ...prevMap[threadId],\n messages: [...prevMessages, chatMessage],\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(currentThreadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n const updatedMessageHistory = [...currentThread.messages, chatMessage];\n\n return updatedMessageHistory;\n },\n [client.beta.threads.messages, currentThread, currentThreadId],\n );\n\n const updateThreadMessage = useCallback(\n async (\n id: string,\n message: TamboThreadMessage,\n sendToServer = true,\n createdAt: string = new Date().toISOString(),\n ) => {\n const chatMessage: TamboThreadMessage = {\n ...message,\n createdAt,\n };\n\n setThreadMap((prevMap) => {\n if (!message.threadId) {\n return prevMap;\n }\n const prevMessages = prevMap[message.threadId]?.messages || [];\n const updatedMessages = prevMessages.map((msg) => {\n if (msg.id === id) {\n return chatMessage;\n }\n return msg;\n });\n return {\n ...prevMap,\n [message.threadId]: {\n ...prevMap[message.threadId],\n messages: updatedMessages,\n },\n };\n });\n if (sendToServer) {\n // TODO: if this fails, we need to revert the local state update\n await client.beta.threads.messages.create(currentThreadId, {\n content: message.content,\n role: message.role,\n // additionalContext: chatMessage.additionalContext,\n });\n }\n },\n [client.beta.threads.messages, currentThreadId],\n );\n\n const deleteThreadMessage = useCallback(\n (messageId: string) => {\n if (!currentThread) return;\n\n setThreadMap((prevMap) => ({\n ...prevMap,\n [currentThread.id]: {\n ...prevMap[currentThread.id],\n messages: prevMap[currentThread.id].messages.filter(\n (msg) => msg.id !== messageId,\n ),\n },\n }));\n },\n [currentThread],\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 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 if (!threadMap[threadId]) {\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [threadId]: {\n ...prevMap[PLACEHOLDER_THREAD.id],\n id: threadId,\n },\n };\n });\n }\n if (fetch) {\n await fetchThread(threadId);\n }\n },\n [fetchThread, threadMap],\n );\n\n const updateThreadStatus = useCallback(\n (stage: GenerationStage, statusMessage?: string) => {\n setThreadMap((prevMap) => {\n return {\n ...prevMap,\n [currentThreadId]: {\n ...prevMap[currentThreadId],\n generationStage: stage,\n statusMessage: statusMessage,\n },\n };\n });\n },\n [currentThreadId],\n );\n\n const handleAdvanceStream = useCallback(\n async (\n stream: AsyncIterable<TamboAI.Beta.Threads.ThreadAdvanceResponse>,\n params: TamboAI.Beta.Threads.ThreadAdvanceParams,\n messageIdToRemove?: string,\n ): Promise<TamboThreadMessage> => {\n let finalMessage: TamboThreadMessage | undefined;\n let hasSetThreadId = false;\n let isFirstChunk = true;\n updateThreadStatus(GenerationStage.STREAMING_RESPONSE);\n\n for await (const chunk of stream) {\n if (isFirstChunk && messageIdToRemove) {\n deleteThreadMessage(messageIdToRemove);\n }\n isFirstChunk = false;\n\n if (chunk.responseMessageDto.toolCallRequest) {\n updateThreadStatus(GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n chunk.responseMessageDto,\n toolRegistry,\n );\n const toolCallResponseString =\n typeof toolCallResponse === \"string\"\n ? toolCallResponse\n : JSON.stringify(toolCallResponse);\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 },\n };\n updateThreadStatus(GenerationStage.STREAMING_RESPONSE);\n const toolCallResponseStream = await advanceStream(\n client,\n toolCallResponseParams,\n chunk.responseMessageDto.threadId,\n );\n\n // Pass the current message's ID to be removed when the new stream starts, since we now know it is a tool call request message\n return await handleAdvanceStream(\n toolCallResponseStream,\n toolCallResponseParams,\n finalMessage?.id,\n );\n } else {\n if (\n !hasSetThreadId &&\n chunk.responseMessageDto.threadId &&\n chunk.responseMessageDto.threadId !== currentThread?.id\n ) {\n hasSetThreadId = true;\n switchCurrentThread(chunk.responseMessageDto.threadId, false);\n }\n\n if (!finalMessage) {\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n addThreadMessage(finalMessage, false);\n } else {\n const previousId = finalMessage.id;\n finalMessage = chunk.responseMessageDto.component?.componentName\n ? renderComponentIntoMessage(\n chunk.responseMessageDto,\n componentList,\n )\n : chunk.responseMessageDto;\n updateThreadMessage(previousId, finalMessage, false);\n }\n }\n }\n\n updateThreadStatus(GenerationStage.COMPLETE);\n if (finalMessage) {\n await fetchThread(finalMessage.threadId);\n }\n return (\n finalMessage ?? {\n threadId: \"\",\n content: [{ type: \"text\", text: `Error processing stream` }],\n role: \"hydra\",\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 deleteThreadMessage,\n fetchThread,\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 contextKey?: string;\n } = {},\n ): Promise<TamboThreadMessage> => {\n const { threadId, streamResponse } = options;\n const currentThreadId = threadId ?? currentThread?.id;\n\n if (currentThreadId !== PLACEHOLDER_THREAD.id) {\n await switchCurrentThread(currentThreadId);\n }\n\n updateThreadStatus(GenerationStage.CHOOSING_COMPONENT);\n\n addThreadMessage(\n {\n content: [{ type: \"text\", text: message }],\n renderedComponent: null,\n role: \"user\",\n threadId: currentThread.id,\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n componentState: {},\n },\n false,\n );\n\n const availableComponents = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n const params: TamboAI.Beta.Threads.ThreadAdvanceParams = {\n messageToAppend: {\n content: [{ type: \"text\", text: message }],\n role: \"user\",\n },\n contextKey: options.contextKey,\n availableComponents: availableComponents,\n };\n\n if (streamResponse) {\n const advanceStreamResponse = await advanceStream(\n client,\n params,\n currentThreadId === PLACEHOLDER_THREAD.id\n ? undefined\n : currentThreadId,\n );\n return await handleAdvanceStream(advanceStreamResponse, params);\n }\n let advanceResponse = await (currentThreadId === PLACEHOLDER_THREAD.id\n ? client.beta.threads.advance(params)\n : client.beta.threads.advanceById(currentThreadId, params));\n\n //handle tool calls\n while (advanceResponse.responseMessageDto.toolCallRequest) {\n updateThreadStatus(GenerationStage.FETCHING_CONTEXT);\n const toolCallResponse = await handleToolCall(\n advanceResponse.responseMessageDto,\n toolRegistry,\n );\n const toolResponseString =\n typeof toolCallResponse === \"string\"\n ? toolCallResponse\n : JSON.stringify(toolCallResponse);\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 },\n };\n updateThreadStatus(GenerationStage.HYDRATING_COMPONENT);\n advanceResponse = await client.beta.threads.advanceById(\n advanceResponse.responseMessageDto.threadId,\n toolCallResponseParams,\n );\n }\n\n const finalMessage = advanceResponse.responseMessageDto.component\n ?.componentName\n ? renderComponentIntoMessage(\n advanceResponse.responseMessageDto,\n componentList,\n )\n : advanceResponse.responseMessageDto;\n await switchCurrentThread(advanceResponse.responseMessageDto.threadId);\n updateThreadStatus(GenerationStage.COMPLETE);\n return finalMessage;\n },\n [\n componentList,\n toolRegistry,\n componentToolAssociations,\n currentThread,\n switchCurrentThread,\n addThreadMessage,\n client,\n updateThreadStatus,\n handleAdvanceStream,\n ],\n );\n\n return (\n <TamboThreadContext.Provider\n value={{\n thread: currentThread,\n switchCurrentThread,\n startNewThread,\n addThreadMessage,\n updateThreadMessage,\n inputValue,\n setInputValue,\n sendThreadMessage,\n generationStage: (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n generationStatusMessage: currentThread?.statusMessage ?? \"\",\n isIdle: isIdleStage(\n (currentThread?.generationStage ??\n GenerationStage.IDLE) as GenerationStage,\n ),\n }}\n >\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * The useTamboThread hook provides access to the current thread context\n * to the descendants of the TamboThreadProvider.\n * @returns All state and actions for the current thread\n */\nexport const useTamboThread = () => {\n const context = useContext(TamboThreadContext);\n if (context === undefined) {\n throw new Error(\"useTamboThread must be used within a TamboThreadProvider\");\n }\n return context;\n};\n"]}
@@ -2,7 +2,11 @@ import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import { ComponentRegistry } from "../model/component-metadata";
3
3
  import { TamboThreadMessage } from "../model/generate-component-response";
4
4
  /**
5
- * Generate a message that has a component rendered into it, if the message came with one
5
+ * Generate a message that has a component rendered into it, if the message
6
+ * came with one.
7
+ * @param message - The message that may contain a component
8
+ * @param componentList - the list of available components
9
+ * @returns The updated message with the component rendered into it
6
10
  */
7
11
  export declare function renderComponentIntoMessage(message: TamboAI.Beta.Threads.ThreadMessage, componentList: ComponentRegistry): TamboThreadMessage;
8
12
  //# sourceMappingURL=generate-component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-component.d.ts","sourceRoot":"","sources":["../../src/util/generate-component.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAC3C,aAAa,EAAE,iBAAiB,GAC/B,kBAAkB,CAiCpB"}
1
+ {"version":3,"file":"generate-component.d.ts","sourceRoot":"","sources":["../../src/util/generate-component.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAC3C,aAAa,EAAE,iBAAiB,GAC/B,kBAAkB,CAiCpB"}
@@ -10,7 +10,11 @@ const zod_1 = require("zod");
10
10
  const use_current_message_1 = require("../hooks/use-current-message");
11
11
  const registry_1 = require("../util/registry");
12
12
  /**
13
- * Generate a message that has a component rendered into it, if the message came with one
13
+ * Generate a message that has a component rendered into it, if the message
14
+ * came with one.
15
+ * @param message - The message that may contain a component
16
+ * @param componentList - the list of available components
17
+ * @returns The updated message with the component rendered into it
14
18
  */
15
19
  function renderComponentIntoMessage(message, componentList) {
16
20
  if (!message.component?.componentName) {
@@ -1 +1 @@
1
- {"version":3,"file":"generate-component.js","sourceRoot":"","sources":["../../src/util/generate-component.ts"],"names":[],"mappings":";;;;;AAYA,gEAoCC;AA/CD,+CAAqC;AACrC,kDAA0B;AAC1B,6BAAwB;AACxB,sEAA4E;AAG5E,+CAA4D;AAE5D;;GAEG;AACH,SAAgB,0BAA0B,CACxC,OAA2C,EAC3C,aAAgC;IAEhC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,WAAW,GAAG,IAAA,oBAAK,EAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,MAAM,mBAAmB,GAAG,IAAA,mCAAwB,EAClD,OAAO,CAAC,SAAS,CAAC,aAAa,EAC/B,aAAa,CACd,CAAC;IAEF,MAAM,cAAc,GAClB,mBAAmB,CAAC,KAAK,YAAY,OAAC,CAAC,OAAO;QAC5C,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;QAC9C,CAAC,CAAC,WAAW,CAAC;IAElB,MAAM,iBAAiB,GAAG,eAAK,CAAC,aAAa,CAC3C,mBAAmB,CAAC,SAAS,EAC7B,cAAc,CACf,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAA,kDAA4B,EACnD,iBAAiB,EACjB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,EAAE,CACX,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,SAAS,EAAE;YACT,GAAG,OAAO,CAAC,SAAS;YACpB,KAAK,EAAE,cAAc;SACtB;QACD,iBAAiB,EAAE,gBAAgB;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { parse } from \"partial-json\";\nimport React from \"react\";\nimport { z } from \"zod\";\nimport { wrapWithTamboMessageProvider } from \"../hooks/use-current-message\";\nimport { ComponentRegistry } from \"../model/component-metadata\";\nimport { TamboThreadMessage } from \"../model/generate-component-response\";\nimport { getComponentFromRegistry } from \"../util/registry\";\n\n/**\n * Generate a message that has a component rendered into it, if the message came with one\n */\nexport function renderComponentIntoMessage(\n message: TamboAI.Beta.Threads.ThreadMessage,\n componentList: ComponentRegistry,\n): TamboThreadMessage {\n if (!message.component?.componentName) {\n throw new Error(\"Component not found\");\n }\n const parsedProps = parse(JSON.stringify(message.component.props));\n const registeredComponent = getComponentFromRegistry(\n message.component.componentName,\n componentList,\n );\n\n const validatedProps =\n registeredComponent.props instanceof z.ZodType\n ? registeredComponent.props.parse(parsedProps)\n : parsedProps;\n\n const renderedComponent = React.createElement(\n registeredComponent.component,\n validatedProps,\n );\n const wrappedComponent = wrapWithTamboMessageProvider(\n renderedComponent,\n message.threadId,\n message.id,\n );\n\n return {\n ...message,\n component: {\n ...message.component,\n props: validatedProps,\n },\n renderedComponent: wrappedComponent,\n };\n}\n"]}
1
+ {"version":3,"file":"generate-component.js","sourceRoot":"","sources":["../../src/util/generate-component.ts"],"names":[],"mappings":";;;;;AAgBA,gEAoCC;AAnDD,+CAAqC;AACrC,kDAA0B;AAC1B,6BAAwB;AACxB,sEAA4E;AAG5E,+CAA4D;AAE5D;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,OAA2C,EAC3C,aAAgC;IAEhC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,WAAW,GAAG,IAAA,oBAAK,EAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,MAAM,mBAAmB,GAAG,IAAA,mCAAwB,EAClD,OAAO,CAAC,SAAS,CAAC,aAAa,EAC/B,aAAa,CACd,CAAC;IAEF,MAAM,cAAc,GAClB,mBAAmB,CAAC,KAAK,YAAY,OAAC,CAAC,OAAO;QAC5C,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;QAC9C,CAAC,CAAC,WAAW,CAAC;IAElB,MAAM,iBAAiB,GAAG,eAAK,CAAC,aAAa,CAC3C,mBAAmB,CAAC,SAAS,EAC7B,cAAc,CACf,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAA,kDAA4B,EACnD,iBAAiB,EACjB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,EAAE,CACX,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,SAAS,EAAE;YACT,GAAG,OAAO,CAAC,SAAS;YACpB,KAAK,EAAE,cAAc;SACtB;QACD,iBAAiB,EAAE,gBAAgB;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { parse } from \"partial-json\";\nimport React from \"react\";\nimport { z } from \"zod\";\nimport { wrapWithTamboMessageProvider } from \"../hooks/use-current-message\";\nimport { ComponentRegistry } from \"../model/component-metadata\";\nimport { TamboThreadMessage } from \"../model/generate-component-response\";\nimport { getComponentFromRegistry } from \"../util/registry\";\n\n/**\n * Generate a message that has a component rendered into it, if the message\n * came with one.\n * @param message - The message that may contain a component\n * @param componentList - the list of available components\n * @returns The updated message with the component rendered into it\n */\nexport function renderComponentIntoMessage(\n message: TamboAI.Beta.Threads.ThreadMessage,\n componentList: ComponentRegistry,\n): TamboThreadMessage {\n if (!message.component?.componentName) {\n throw new Error(\"Component not found\");\n }\n const parsedProps = parse(JSON.stringify(message.component.props));\n const registeredComponent = getComponentFromRegistry(\n message.component.componentName,\n componentList,\n );\n\n const validatedProps =\n registeredComponent.props instanceof z.ZodType\n ? registeredComponent.props.parse(parsedProps)\n : parsedProps;\n\n const renderedComponent = React.createElement(\n registeredComponent.component,\n validatedProps,\n );\n const wrappedComponent = wrapWithTamboMessageProvider(\n renderedComponent,\n message.threadId,\n message.id,\n );\n\n return {\n ...message,\n component: {\n ...message.component,\n props: validatedProps,\n },\n renderedComponent: wrappedComponent,\n };\n}\n"]}
@@ -1,6 +1,22 @@
1
1
  import { UseMutationResult, UseQueryResult } from "@tanstack/react-query";
2
2
  export type CombinedMutationResult<TData = unknown, TError = unknown, TVariables = unknown, TContext = unknown> = Omit<UseMutationResult<TData, TError, TVariables, TContext>, "mutate" | "mutateAsync" | "reset" | "data" | "variables" | "context">;
3
+ /**
4
+ * Combines two mutation results, showing the "loading state" of the two
5
+ * mutations. For instance, if either mutation is pending, the combined
6
+ * mutation result will be pending.
7
+ * @param resultA - The first mutation result
8
+ * @param resultB - The second mutation result
9
+ * @returns The combined mutation result
10
+ */
3
11
  export declare function combineMutationResults<TData1, TData2, TError1, TError2>(resultA: UseMutationResult<TData1, TError1, any, any>, resultB: UseMutationResult<TData2, TError2, any, any>): CombinedMutationResult<TData1 | TData2, TError1 | TError2>;
4
12
  export type CombinedQueryResult<TData1, TData2, TError1, TError2> = Omit<UseQueryResult<TData1 | TData2, TError1 | TError2>, "data" | "refetch" | "promise">;
13
+ /**
14
+ * Combines two query results, showing the "loading state" of the two queries.
15
+ * For instance, if either query is loading, the combined query result will be
16
+ * loading.
17
+ * @param resultA - The first query result
18
+ * @param resultB - The second query result
19
+ * @returns The combined query result
20
+ */
5
21
  export declare function combineQueryResults<TData1, TData2, TError1, TError2>(resultA: UseQueryResult<TData1, TError1>, resultB: UseQueryResult<TData2, TError2>): CombinedQueryResult<void, void, TError1, TError2>;
6
22
  //# sourceMappingURL=query-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-utils.d.ts","sourceRoot":"","sources":["../../src/util/query-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE1E,MAAM,MAAM,sBAAsB,CAChC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,OAAO,EAChB,UAAU,GAAG,OAAO,EACpB,QAAQ,GAAG,OAAO,IAChB,IAAI,CACN,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,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AO,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CACtE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EACrE,OAAO,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,EACrD,OAAO,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GACpD,sBAAsB,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,CAsB5D;AAED,MAAM,MAAM,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,CACtE,cAAc,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,EAClD,MAAM,GAAG,SAAS,GAAG,SAAS,CAC/B,CAAC;AACF;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAClE,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAsCnD"}
@@ -2,6 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.combineMutationResults = combineMutationResults;
4
4
  exports.combineQueryResults = combineQueryResults;
5
+ /**
6
+ * Combines two mutation results, showing the "loading state" of the two
7
+ * mutations. For instance, if either mutation is pending, the combined
8
+ * mutation result will be pending.
9
+ * @param resultA - The first mutation result
10
+ * @param resultB - The second mutation result
11
+ * @returns The combined mutation result
12
+ */
5
13
  function combineMutationResults(resultA, resultB) {
6
14
  {
7
15
  return {
@@ -24,6 +32,14 @@ function combineMutationResults(resultA, resultB) {
24
32
  };
25
33
  }
26
34
  }
35
+ /**
36
+ * Combines two query results, showing the "loading state" of the two queries.
37
+ * For instance, if either query is loading, the combined query result will be
38
+ * loading.
39
+ * @param resultA - The first query result
40
+ * @param resultB - The second query result
41
+ * @returns The combined query result
42
+ */
27
43
  function combineQueryResults(resultA, resultB) {
28
44
  return {
29
45
  isPending: resultA.isPending || resultB.isPending,