@tambo-ai/react 0.75.0 → 1.0.0-rc.4

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 (613) hide show
  1. package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
  2. package/dist/hoc/with-tambo-interactable.js +13 -13
  3. package/dist/hoc/with-tambo-interactable.js.map +1 -1
  4. package/dist/hoc/with-tambo-interactable.test.js +3 -3
  5. package/dist/hoc/with-tambo-interactable.test.js.map +1 -1
  6. package/dist/index.d.ts +7 -25
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +7 -59
  9. package/dist/index.js.map +1 -1
  10. package/dist/mcp/mcp-hooks.js +5 -5
  11. package/dist/mcp/mcp-hooks.js.map +1 -1
  12. package/dist/model/component-metadata.d.ts +4 -4
  13. package/dist/model/component-metadata.js.map +1 -1
  14. package/dist/providers/tambo-client-provider.d.ts +6 -0
  15. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  16. package/dist/providers/tambo-client-provider.js +4 -2
  17. package/dist/providers/tambo-client-provider.js.map +1 -1
  18. package/dist/providers/tambo-interactable-provider.d.ts +1 -1
  19. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +2 -10
  20. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  21. package/dist/providers/tambo-interactables-additional-context.test.js +3 -19
  22. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  23. package/dist/providers/tambo-mcp-token-provider.d.ts +8 -17
  24. package/dist/providers/tambo-mcp-token-provider.d.ts.map +1 -1
  25. package/dist/providers/tambo-mcp-token-provider.js +20 -97
  26. package/dist/providers/tambo-mcp-token-provider.js.map +1 -1
  27. package/dist/testing/tools.d.ts +3 -3
  28. package/dist/testing/tools.d.ts.map +1 -1
  29. package/dist/testing/tools.js.map +1 -1
  30. package/dist/util/registry-validators.js +1 -1
  31. package/dist/util/registry-validators.js.map +1 -1
  32. package/dist/v1/__tests__/v1-interactables.test.js +1 -1
  33. package/dist/v1/__tests__/v1-interactables.test.js.map +1 -1
  34. package/dist/v1/components/v1-component-renderer.d.ts +9 -9
  35. package/dist/v1/components/v1-component-renderer.d.ts.map +1 -1
  36. package/dist/v1/components/v1-component-renderer.js +13 -13
  37. package/dist/v1/components/v1-component-renderer.js.map +1 -1
  38. package/dist/v1/components/v1-component-renderer.test.js +15 -15
  39. package/dist/v1/components/v1-component-renderer.test.js.map +1 -1
  40. package/{esm/hooks/use-current-message.d.ts → dist/v1/hooks/use-tambo-current-message.d.ts} +30 -9
  41. package/dist/v1/hooks/use-tambo-current-message.d.ts.map +1 -0
  42. package/dist/{hooks/use-current-message.js → v1/hooks/use-tambo-current-message.js} +13 -8
  43. package/dist/v1/hooks/use-tambo-current-message.js.map +1 -0
  44. package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts +5 -5
  45. package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
  46. package/dist/v1/hooks/use-tambo-v1-auth-state.js +8 -8
  47. package/dist/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
  48. package/dist/v1/hooks/use-tambo-v1-auth-state.test.js +12 -12
  49. package/dist/v1/hooks/use-tambo-v1-auth-state.test.js.map +1 -1
  50. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts +7 -6
  51. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
  52. package/dist/v1/hooks/use-tambo-v1-component-state.js +50 -24
  53. package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
  54. package/dist/v1/hooks/use-tambo-v1-component-state.test.js +60 -35
  55. package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
  56. package/dist/v1/hooks/use-tambo-v1-messages.d.ts +9 -9
  57. package/dist/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -1
  58. package/dist/v1/hooks/use-tambo-v1-messages.js +4 -4
  59. package/dist/v1/hooks/use-tambo-v1-messages.js.map +1 -1
  60. package/dist/v1/hooks/use-tambo-v1-messages.test.js +7 -7
  61. package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
  62. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +3 -3
  63. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  64. package/dist/v1/hooks/use-tambo-v1-send-message.js +20 -22
  65. package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  66. package/dist/v1/hooks/use-tambo-v1-send-message.test.js +51 -51
  67. package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  68. package/dist/v1/hooks/use-tambo-v1-stream-status.d.ts +5 -5
  69. package/dist/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -1
  70. package/dist/v1/hooks/use-tambo-v1-stream-status.js +12 -14
  71. package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
  72. package/dist/v1/hooks/use-tambo-v1-stream-status.test.js +19 -19
  73. package/dist/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
  74. package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +7 -7
  75. package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
  76. package/dist/v1/hooks/use-tambo-v1-suggestions.js +9 -9
  77. package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
  78. package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +44 -44
  79. package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
  80. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +3 -3
  81. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
  82. package/dist/v1/hooks/use-tambo-v1-thread-input.js +4 -4
  83. package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
  84. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +29 -29
  85. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
  86. package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +4 -4
  87. package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
  88. package/dist/v1/hooks/use-tambo-v1-thread-list.js +5 -5
  89. package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
  90. package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +13 -17
  91. package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
  92. package/dist/v1/hooks/use-tambo-v1-thread.d.ts +3 -3
  93. package/dist/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
  94. package/dist/v1/hooks/use-tambo-v1-thread.js +4 -4
  95. package/dist/v1/hooks/use-tambo-v1-thread.js.map +1 -1
  96. package/dist/v1/hooks/use-tambo-v1-thread.test.js +5 -5
  97. package/dist/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
  98. package/dist/v1/hooks/use-tambo-v1.d.ts +16 -7
  99. package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -1
  100. package/dist/v1/hooks/use-tambo-v1.js +41 -10
  101. package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
  102. package/dist/v1/hooks/use-tambo-v1.test.js +176 -48
  103. package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
  104. package/dist/v1/index.d.ts +31 -27
  105. package/dist/v1/index.d.ts.map +1 -1
  106. package/dist/v1/index.js +45 -35
  107. package/dist/v1/index.js.map +1 -1
  108. package/dist/v1/providers/tambo-v1-provider.d.ts +20 -20
  109. package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  110. package/dist/v1/providers/tambo-v1-provider.js +32 -32
  111. package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
  112. package/dist/v1/providers/tambo-v1-provider.test.js +22 -22
  113. package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
  114. package/dist/v1/providers/tambo-v1-stream-context.d.ts +15 -15
  115. package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  116. package/dist/v1/providers/tambo-v1-stream-context.js +17 -17
  117. package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
  118. package/dist/v1/providers/tambo-v1-stream-context.test.js +9 -9
  119. package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  120. package/dist/v1/providers/tambo-v1-stub-provider.d.ts +9 -9
  121. package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
  122. package/dist/v1/providers/tambo-v1-stub-provider.js +7 -7
  123. package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
  124. package/dist/v1/providers/tambo-v1-stub-provider.test.js +25 -25
  125. package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
  126. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +9 -9
  127. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
  128. package/dist/v1/providers/tambo-v1-thread-input-provider.js +16 -16
  129. package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
  130. package/dist/v1/types/auth.d.ts +2 -2
  131. package/dist/v1/types/auth.d.ts.map +1 -1
  132. package/dist/v1/types/auth.js.map +1 -1
  133. package/dist/v1/types/component.d.ts +3 -3
  134. package/dist/v1/types/component.d.ts.map +1 -1
  135. package/dist/v1/types/component.js +2 -2
  136. package/dist/v1/types/component.js.map +1 -1
  137. package/dist/v1/types/event.d.ts +1 -1
  138. package/dist/v1/types/event.js +1 -1
  139. package/dist/v1/types/event.js.map +1 -1
  140. package/dist/v1/types/message.d.ts +17 -24
  141. package/dist/v1/types/message.d.ts.map +1 -1
  142. package/dist/v1/types/message.js +1 -1
  143. package/dist/v1/types/message.js.map +1 -1
  144. package/dist/v1/types/thread.d.ts +10 -8
  145. package/dist/v1/types/thread.d.ts.map +1 -1
  146. package/dist/v1/types/thread.js +1 -1
  147. package/dist/v1/types/thread.js.map +1 -1
  148. package/dist/v1/types/tool-choice.d.ts +1 -1
  149. package/dist/v1/types/tool-choice.js.map +1 -1
  150. package/dist/v1/utils/component-renderer.d.ts +11 -5
  151. package/dist/v1/utils/component-renderer.d.ts.map +1 -1
  152. package/dist/v1/utils/component-renderer.js +16 -7
  153. package/dist/v1/utils/component-renderer.js.map +1 -1
  154. package/dist/v1/utils/component-renderer.test.js +7 -7
  155. package/dist/v1/utils/component-renderer.test.js.map +1 -1
  156. package/dist/v1/utils/event-accumulator.d.ts +13 -13
  157. package/dist/v1/utils/event-accumulator.d.ts.map +1 -1
  158. package/dist/v1/utils/event-accumulator.js +26 -15
  159. package/dist/v1/utils/event-accumulator.js.map +1 -1
  160. package/dist/v1/utils/event-accumulator.test.js +54 -19
  161. package/dist/v1/utils/event-accumulator.test.js.map +1 -1
  162. package/dist/v1/utils/registry-conversion.d.ts +18 -18
  163. package/dist/v1/utils/registry-conversion.js +23 -23
  164. package/dist/v1/utils/registry-conversion.js.map +1 -1
  165. package/dist/v1/utils/stream-handler.d.ts +1 -1
  166. package/dist/v1/utils/stream-handler.js +1 -1
  167. package/dist/v1/utils/stream-handler.js.map +1 -1
  168. package/dist/v1/utils/thread-utils.d.ts +2 -2
  169. package/dist/v1/utils/thread-utils.d.ts.map +1 -1
  170. package/dist/v1/utils/thread-utils.js.map +1 -1
  171. package/dist/v1/utils/tool-call-tracker.d.ts +1 -1
  172. package/dist/v1/utils/tool-call-tracker.js +1 -1
  173. package/dist/v1/utils/tool-call-tracker.js.map +1 -1
  174. package/dist/v1/utils/tool-executor.d.ts +1 -1
  175. package/dist/v1/utils/tool-executor.js +2 -2
  176. package/dist/v1/utils/tool-executor.js.map +1 -1
  177. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
  178. package/esm/hoc/with-tambo-interactable.js +13 -13
  179. package/esm/hoc/with-tambo-interactable.js.map +1 -1
  180. package/esm/hoc/with-tambo-interactable.test.js +1 -1
  181. package/esm/hoc/with-tambo-interactable.test.js.map +1 -1
  182. package/esm/index.d.ts +7 -25
  183. package/esm/index.d.ts.map +1 -1
  184. package/esm/index.js +7 -21
  185. package/esm/index.js.map +1 -1
  186. package/esm/mcp/mcp-hooks.js +1 -1
  187. package/esm/mcp/mcp-hooks.js.map +1 -1
  188. package/esm/model/component-metadata.d.ts +4 -4
  189. package/esm/model/component-metadata.js.map +1 -1
  190. package/esm/providers/tambo-client-provider.d.ts +6 -0
  191. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  192. package/esm/providers/tambo-client-provider.js +4 -2
  193. package/esm/providers/tambo-client-provider.js.map +1 -1
  194. package/esm/providers/tambo-interactable-provider.d.ts +1 -1
  195. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +2 -10
  196. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  197. package/esm/providers/tambo-interactables-additional-context.test.js +3 -19
  198. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  199. package/esm/providers/tambo-mcp-token-provider.d.ts +8 -17
  200. package/esm/providers/tambo-mcp-token-provider.d.ts.map +1 -1
  201. package/esm/providers/tambo-mcp-token-provider.js +20 -97
  202. package/esm/providers/tambo-mcp-token-provider.js.map +1 -1
  203. package/esm/testing/tools.d.ts +3 -3
  204. package/esm/testing/tools.d.ts.map +1 -1
  205. package/esm/testing/tools.js.map +1 -1
  206. package/esm/util/registry-validators.js +1 -1
  207. package/esm/util/registry-validators.js.map +1 -1
  208. package/esm/v1/__tests__/v1-interactables.test.js +1 -1
  209. package/esm/v1/__tests__/v1-interactables.test.js.map +1 -1
  210. package/esm/v1/components/v1-component-renderer.d.ts +9 -9
  211. package/esm/v1/components/v1-component-renderer.d.ts.map +1 -1
  212. package/esm/v1/components/v1-component-renderer.js +12 -12
  213. package/esm/v1/components/v1-component-renderer.js.map +1 -1
  214. package/esm/v1/components/v1-component-renderer.test.js +16 -16
  215. package/esm/v1/components/v1-component-renderer.test.js.map +1 -1
  216. package/{dist/hooks/use-current-message.d.ts → esm/v1/hooks/use-tambo-current-message.d.ts} +30 -9
  217. package/esm/v1/hooks/use-tambo-current-message.d.ts.map +1 -0
  218. package/esm/{hooks/use-current-message.js → v1/hooks/use-tambo-current-message.js} +13 -8
  219. package/esm/v1/hooks/use-tambo-current-message.js.map +1 -0
  220. package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts +5 -5
  221. package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
  222. package/esm/v1/hooks/use-tambo-v1-auth-state.js +8 -8
  223. package/esm/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
  224. package/esm/v1/hooks/use-tambo-v1-auth-state.test.js +14 -14
  225. package/esm/v1/hooks/use-tambo-v1-auth-state.test.js.map +1 -1
  226. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts +7 -6
  227. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
  228. package/esm/v1/hooks/use-tambo-v1-component-state.js +50 -24
  229. package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
  230. package/esm/v1/hooks/use-tambo-v1-component-state.test.js +62 -37
  231. package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
  232. package/esm/v1/hooks/use-tambo-v1-messages.d.ts +9 -9
  233. package/esm/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -1
  234. package/esm/v1/hooks/use-tambo-v1-messages.js +3 -3
  235. package/esm/v1/hooks/use-tambo-v1-messages.js.map +1 -1
  236. package/esm/v1/hooks/use-tambo-v1-messages.test.js +9 -9
  237. package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
  238. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +3 -3
  239. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  240. package/esm/v1/hooks/use-tambo-v1-send-message.js +21 -23
  241. package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  242. package/esm/v1/hooks/use-tambo-v1-send-message.test.js +54 -54
  243. package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  244. package/esm/v1/hooks/use-tambo-v1-stream-status.d.ts +5 -5
  245. package/esm/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -1
  246. package/esm/v1/hooks/use-tambo-v1-stream-status.js +12 -14
  247. package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
  248. package/esm/v1/hooks/use-tambo-v1-stream-status.test.js +21 -21
  249. package/esm/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
  250. package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +7 -7
  251. package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
  252. package/esm/v1/hooks/use-tambo-v1-suggestions.js +11 -11
  253. package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
  254. package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +48 -48
  255. package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
  256. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +3 -3
  257. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
  258. package/esm/v1/hooks/use-tambo-v1-thread-input.js +3 -3
  259. package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
  260. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +32 -32
  261. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
  262. package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +4 -4
  263. package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
  264. package/esm/v1/hooks/use-tambo-v1-thread-list.js +6 -6
  265. package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
  266. package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +15 -19
  267. package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
  268. package/esm/v1/hooks/use-tambo-v1-thread.d.ts +3 -3
  269. package/esm/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
  270. package/esm/v1/hooks/use-tambo-v1-thread.js +4 -4
  271. package/esm/v1/hooks/use-tambo-v1-thread.js.map +1 -1
  272. package/esm/v1/hooks/use-tambo-v1-thread.test.js +6 -6
  273. package/esm/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
  274. package/esm/v1/hooks/use-tambo-v1.d.ts +16 -7
  275. package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -1
  276. package/esm/v1/hooks/use-tambo-v1.js +43 -12
  277. package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
  278. package/esm/v1/hooks/use-tambo-v1.test.js +178 -50
  279. package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
  280. package/esm/v1/index.d.ts +31 -27
  281. package/esm/v1/index.d.ts.map +1 -1
  282. package/esm/v1/index.js +38 -33
  283. package/esm/v1/index.js.map +1 -1
  284. package/esm/v1/providers/tambo-v1-provider.d.ts +20 -20
  285. package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  286. package/esm/v1/providers/tambo-v1-provider.js +32 -32
  287. package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
  288. package/esm/v1/providers/tambo-v1-provider.test.js +23 -23
  289. package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
  290. package/esm/v1/providers/tambo-v1-stream-context.d.ts +15 -15
  291. package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  292. package/esm/v1/providers/tambo-v1-stream-context.js +17 -17
  293. package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
  294. package/esm/v1/providers/tambo-v1-stream-context.test.js +10 -10
  295. package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  296. package/esm/v1/providers/tambo-v1-stub-provider.d.ts +9 -9
  297. package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
  298. package/esm/v1/providers/tambo-v1-stub-provider.js +9 -9
  299. package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
  300. package/esm/v1/providers/tambo-v1-stub-provider.test.js +28 -28
  301. package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
  302. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +9 -9
  303. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
  304. package/esm/v1/providers/tambo-v1-thread-input-provider.js +15 -15
  305. package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
  306. package/esm/v1/types/auth.d.ts +2 -2
  307. package/esm/v1/types/auth.d.ts.map +1 -1
  308. package/esm/v1/types/auth.js.map +1 -1
  309. package/esm/v1/types/component.d.ts +3 -3
  310. package/esm/v1/types/component.d.ts.map +1 -1
  311. package/esm/v1/types/component.js +2 -2
  312. package/esm/v1/types/component.js.map +1 -1
  313. package/esm/v1/types/event.d.ts +1 -1
  314. package/esm/v1/types/event.js +1 -1
  315. package/esm/v1/types/event.js.map +1 -1
  316. package/esm/v1/types/message.d.ts +17 -24
  317. package/esm/v1/types/message.d.ts.map +1 -1
  318. package/esm/v1/types/message.js +1 -1
  319. package/esm/v1/types/message.js.map +1 -1
  320. package/esm/v1/types/thread.d.ts +10 -8
  321. package/esm/v1/types/thread.d.ts.map +1 -1
  322. package/esm/v1/types/thread.js +1 -1
  323. package/esm/v1/types/thread.js.map +1 -1
  324. package/esm/v1/types/tool-choice.d.ts +1 -1
  325. package/esm/v1/types/tool-choice.js.map +1 -1
  326. package/esm/v1/utils/component-renderer.d.ts +11 -5
  327. package/esm/v1/utils/component-renderer.d.ts.map +1 -1
  328. package/esm/v1/utils/component-renderer.js +13 -5
  329. package/esm/v1/utils/component-renderer.js.map +1 -1
  330. package/esm/v1/utils/component-renderer.test.js +8 -8
  331. package/esm/v1/utils/component-renderer.test.js.map +1 -1
  332. package/esm/v1/utils/event-accumulator.d.ts +13 -13
  333. package/esm/v1/utils/event-accumulator.d.ts.map +1 -1
  334. package/esm/v1/utils/event-accumulator.js +26 -15
  335. package/esm/v1/utils/event-accumulator.js.map +1 -1
  336. package/esm/v1/utils/event-accumulator.test.js +54 -19
  337. package/esm/v1/utils/event-accumulator.test.js.map +1 -1
  338. package/esm/v1/utils/registry-conversion.d.ts +18 -18
  339. package/esm/v1/utils/registry-conversion.js +23 -23
  340. package/esm/v1/utils/registry-conversion.js.map +1 -1
  341. package/esm/v1/utils/stream-handler.d.ts +1 -1
  342. package/esm/v1/utils/stream-handler.js +1 -1
  343. package/esm/v1/utils/stream-handler.js.map +1 -1
  344. package/esm/v1/utils/thread-utils.d.ts +2 -2
  345. package/esm/v1/utils/thread-utils.d.ts.map +1 -1
  346. package/esm/v1/utils/thread-utils.js.map +1 -1
  347. package/esm/v1/utils/tool-call-tracker.d.ts +1 -1
  348. package/esm/v1/utils/tool-call-tracker.js +1 -1
  349. package/esm/v1/utils/tool-call-tracker.js.map +1 -1
  350. package/esm/v1/utils/tool-executor.d.ts +1 -1
  351. package/esm/v1/utils/tool-executor.js +2 -2
  352. package/esm/v1/utils/tool-executor.js.map +1 -1
  353. package/package.json +4 -9
  354. package/dist/hooks/index.d.ts +0 -9
  355. package/dist/hooks/index.d.ts.map +0 -1
  356. package/dist/hooks/index.js +0 -34
  357. package/dist/hooks/index.js.map +0 -1
  358. package/dist/hooks/use-component-state.d.ts +0 -30
  359. package/dist/hooks/use-component-state.d.ts.map +0 -1
  360. package/dist/hooks/use-component-state.js +0 -139
  361. package/dist/hooks/use-component-state.js.map +0 -1
  362. package/dist/hooks/use-component-state.test.d.ts +0 -2
  363. package/dist/hooks/use-component-state.test.d.ts.map +0 -1
  364. package/dist/hooks/use-component-state.test.js +0 -406
  365. package/dist/hooks/use-component-state.test.js.map +0 -1
  366. package/dist/hooks/use-current-message.d.ts.map +0 -1
  367. package/dist/hooks/use-current-message.js.map +0 -1
  368. package/dist/hooks/use-current-message.test.d.ts +0 -2
  369. package/dist/hooks/use-current-message.test.d.ts.map +0 -1
  370. package/dist/hooks/use-current-message.test.js +0 -269
  371. package/dist/hooks/use-current-message.test.js.map +0 -1
  372. package/dist/hooks/use-streaming-props.d.ts +0 -11
  373. package/dist/hooks/use-streaming-props.d.ts.map +0 -1
  374. package/dist/hooks/use-streaming-props.js +0 -37
  375. package/dist/hooks/use-streaming-props.js.map +0 -1
  376. package/dist/hooks/use-suggestions.d.ts +0 -46
  377. package/dist/hooks/use-suggestions.d.ts.map +0 -1
  378. package/dist/hooks/use-suggestions.js +0 -118
  379. package/dist/hooks/use-suggestions.js.map +0 -1
  380. package/dist/hooks/use-suggestions.test.d.ts +0 -2
  381. package/dist/hooks/use-suggestions.test.d.ts.map +0 -1
  382. package/dist/hooks/use-suggestions.test.js +0 -247
  383. package/dist/hooks/use-suggestions.test.js.map +0 -1
  384. package/dist/hooks/use-tambo-stream-status.d.ts +0 -90
  385. package/dist/hooks/use-tambo-stream-status.d.ts.map +0 -1
  386. package/dist/hooks/use-tambo-stream-status.js +0 -213
  387. package/dist/hooks/use-tambo-stream-status.js.map +0 -1
  388. package/dist/hooks/use-tambo-stream-status.test.d.ts +0 -2
  389. package/dist/hooks/use-tambo-stream-status.test.d.ts.map +0 -1
  390. package/dist/hooks/use-tambo-stream-status.test.js +0 -378
  391. package/dist/hooks/use-tambo-stream-status.test.js.map +0 -1
  392. package/dist/hooks/use-tambo-threads.d.ts +0 -158
  393. package/dist/hooks/use-tambo-threads.d.ts.map +0 -1
  394. package/dist/hooks/use-tambo-threads.js +0 -45
  395. package/dist/hooks/use-tambo-threads.js.map +0 -1
  396. package/dist/hooks/use-tambo-threads.test.d.ts +0 -2
  397. package/dist/hooks/use-tambo-threads.test.d.ts.map +0 -1
  398. package/dist/hooks/use-tambo-threads.test.js +0 -214
  399. package/dist/hooks/use-tambo-threads.test.js.map +0 -1
  400. package/dist/model/generate-component-response.d.ts +0 -37
  401. package/dist/model/generate-component-response.d.ts.map +0 -1
  402. package/dist/model/generate-component-response.js +0 -29
  403. package/dist/model/generate-component-response.js.map +0 -1
  404. package/dist/model/tambo-thread.d.ts +0 -15
  405. package/dist/model/tambo-thread.d.ts.map +0 -1
  406. package/dist/model/tambo-thread.js +0 -3
  407. package/dist/model/tambo-thread.js.map +0 -1
  408. package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts +0 -2
  409. package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +0 -1
  410. package/dist/providers/__tests__/thread-input-resource-resolution.test.js +0 -592
  411. package/dist/providers/__tests__/thread-input-resource-resolution.test.js.map +0 -1
  412. package/dist/providers/index.d.ts +0 -13
  413. package/dist/providers/index.d.ts.map +0 -1
  414. package/dist/providers/index.js +0 -41
  415. package/dist/providers/index.js.map +0 -1
  416. package/dist/providers/tambo-component-provider.d.ts +0 -23
  417. package/dist/providers/tambo-component-provider.d.ts.map +0 -1
  418. package/dist/providers/tambo-component-provider.js +0 -88
  419. package/dist/providers/tambo-component-provider.js.map +0 -1
  420. package/dist/providers/tambo-prop-stream-provider/index.d.ts +0 -19
  421. package/dist/providers/tambo-prop-stream-provider/index.d.ts.map +0 -1
  422. package/dist/providers/tambo-prop-stream-provider/index.js +0 -43
  423. package/dist/providers/tambo-prop-stream-provider/index.js.map +0 -1
  424. package/dist/providers/tambo-prop-stream-provider/pending.d.ts +0 -12
  425. package/dist/providers/tambo-prop-stream-provider/pending.d.ts.map +0 -1
  426. package/dist/providers/tambo-prop-stream-provider/pending.js +0 -31
  427. package/dist/providers/tambo-prop-stream-provider/pending.js.map +0 -1
  428. package/dist/providers/tambo-prop-stream-provider/provider.d.ts +0 -17
  429. package/dist/providers/tambo-prop-stream-provider/provider.d.ts.map +0 -1
  430. package/dist/providers/tambo-prop-stream-provider/provider.js +0 -107
  431. package/dist/providers/tambo-prop-stream-provider/provider.js.map +0 -1
  432. package/dist/providers/tambo-prop-stream-provider/streaming.d.ts +0 -12
  433. package/dist/providers/tambo-prop-stream-provider/streaming.d.ts.map +0 -1
  434. package/dist/providers/tambo-prop-stream-provider/streaming.js +0 -28
  435. package/dist/providers/tambo-prop-stream-provider/streaming.js.map +0 -1
  436. package/dist/providers/tambo-prop-stream-provider/success.d.ts +0 -12
  437. package/dist/providers/tambo-prop-stream-provider/success.d.ts.map +0 -1
  438. package/dist/providers/tambo-prop-stream-provider/success.js +0 -28
  439. package/dist/providers/tambo-prop-stream-provider/success.js.map +0 -1
  440. package/dist/providers/tambo-prop-stream-provider/types.d.ts +0 -25
  441. package/dist/providers/tambo-prop-stream-provider/types.d.ts.map +0 -1
  442. package/dist/providers/tambo-prop-stream-provider/types.js +0 -6
  443. package/dist/providers/tambo-prop-stream-provider/types.js.map +0 -1
  444. package/dist/providers/tambo-prop-stream-provider.test.d.ts +0 -2
  445. package/dist/providers/tambo-prop-stream-provider.test.d.ts.map +0 -1
  446. package/dist/providers/tambo-prop-stream-provider.test.js +0 -275
  447. package/dist/providers/tambo-prop-stream-provider.test.js.map +0 -1
  448. package/dist/providers/tambo-provider.d.ts +0 -53
  449. package/dist/providers/tambo-provider.d.ts.map +0 -1
  450. package/dist/providers/tambo-provider.js +0 -133
  451. package/dist/providers/tambo-provider.js.map +0 -1
  452. package/dist/providers/tambo-stubs.d.ts +0 -89
  453. package/dist/providers/tambo-stubs.d.ts.map +0 -1
  454. package/dist/providers/tambo-stubs.js +0 -279
  455. package/dist/providers/tambo-stubs.js.map +0 -1
  456. package/dist/providers/tambo-stubs.test.d.ts +0 -2
  457. package/dist/providers/tambo-stubs.test.d.ts.map +0 -1
  458. package/dist/providers/tambo-stubs.test.js +0 -97
  459. package/dist/providers/tambo-stubs.test.js.map +0 -1
  460. package/dist/providers/tambo-thread-input-provider.d.ts +0 -65
  461. package/dist/providers/tambo-thread-input-provider.d.ts.map +0 -1
  462. package/dist/providers/tambo-thread-input-provider.js +0 -179
  463. package/dist/providers/tambo-thread-input-provider.js.map +0 -1
  464. package/dist/providers/tambo-thread-provider-initial-messages.test.d.ts +0 -2
  465. package/dist/providers/tambo-thread-provider-initial-messages.test.d.ts.map +0 -1
  466. package/dist/providers/tambo-thread-provider-initial-messages.test.js +0 -278
  467. package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +0 -1
  468. package/dist/providers/tambo-thread-provider.d.ts +0 -126
  469. package/dist/providers/tambo-thread-provider.d.ts.map +0 -1
  470. package/dist/providers/tambo-thread-provider.js +0 -931
  471. package/dist/providers/tambo-thread-provider.js.map +0 -1
  472. package/dist/providers/tambo-thread-provider.test.d.ts +0 -2
  473. package/dist/providers/tambo-thread-provider.test.d.ts.map +0 -1
  474. package/dist/providers/tambo-thread-provider.test.js +0 -1591
  475. package/dist/providers/tambo-thread-provider.test.js.map +0 -1
  476. package/dist/util/generate-component.d.ts +0 -12
  477. package/dist/util/generate-component.d.ts.map +0 -1
  478. package/dist/util/generate-component.js +0 -58
  479. package/dist/util/generate-component.js.map +0 -1
  480. package/dist/util/generate-component.test.d.ts +0 -2
  481. package/dist/util/generate-component.test.d.ts.map +0 -1
  482. package/dist/util/generate-component.test.js +0 -340
  483. package/dist/util/generate-component.test.js.map +0 -1
  484. package/esm/hooks/index.d.ts +0 -9
  485. package/esm/hooks/index.d.ts.map +0 -1
  486. package/esm/hooks/index.js +0 -10
  487. package/esm/hooks/index.js.map +0 -1
  488. package/esm/hooks/use-component-state.d.ts +0 -30
  489. package/esm/hooks/use-component-state.d.ts.map +0 -1
  490. package/esm/hooks/use-component-state.js +0 -136
  491. package/esm/hooks/use-component-state.js.map +0 -1
  492. package/esm/hooks/use-component-state.test.d.ts +0 -2
  493. package/esm/hooks/use-component-state.test.d.ts.map +0 -1
  494. package/esm/hooks/use-component-state.test.js +0 -401
  495. package/esm/hooks/use-component-state.test.js.map +0 -1
  496. package/esm/hooks/use-current-message.d.ts.map +0 -1
  497. package/esm/hooks/use-current-message.js.map +0 -1
  498. package/esm/hooks/use-current-message.test.d.ts +0 -2
  499. package/esm/hooks/use-current-message.test.d.ts.map +0 -1
  500. package/esm/hooks/use-current-message.test.js +0 -264
  501. package/esm/hooks/use-current-message.test.js.map +0 -1
  502. package/esm/hooks/use-streaming-props.d.ts +0 -11
  503. package/esm/hooks/use-streaming-props.d.ts.map +0 -1
  504. package/esm/hooks/use-streaming-props.js +0 -34
  505. package/esm/hooks/use-streaming-props.js.map +0 -1
  506. package/esm/hooks/use-suggestions.d.ts +0 -46
  507. package/esm/hooks/use-suggestions.d.ts.map +0 -1
  508. package/esm/hooks/use-suggestions.js +0 -115
  509. package/esm/hooks/use-suggestions.js.map +0 -1
  510. package/esm/hooks/use-suggestions.test.d.ts +0 -2
  511. package/esm/hooks/use-suggestions.test.d.ts.map +0 -1
  512. package/esm/hooks/use-suggestions.test.js +0 -245
  513. package/esm/hooks/use-suggestions.test.js.map +0 -1
  514. package/esm/hooks/use-tambo-stream-status.d.ts +0 -90
  515. package/esm/hooks/use-tambo-stream-status.d.ts.map +0 -1
  516. package/esm/hooks/use-tambo-stream-status.js +0 -210
  517. package/esm/hooks/use-tambo-stream-status.js.map +0 -1
  518. package/esm/hooks/use-tambo-stream-status.test.d.ts +0 -2
  519. package/esm/hooks/use-tambo-stream-status.test.d.ts.map +0 -1
  520. package/esm/hooks/use-tambo-stream-status.test.js +0 -376
  521. package/esm/hooks/use-tambo-stream-status.test.js.map +0 -1
  522. package/esm/hooks/use-tambo-threads.d.ts +0 -158
  523. package/esm/hooks/use-tambo-threads.d.ts.map +0 -1
  524. package/esm/hooks/use-tambo-threads.js +0 -42
  525. package/esm/hooks/use-tambo-threads.js.map +0 -1
  526. package/esm/hooks/use-tambo-threads.test.d.ts +0 -2
  527. package/esm/hooks/use-tambo-threads.test.d.ts.map +0 -1
  528. package/esm/hooks/use-tambo-threads.test.js +0 -212
  529. package/esm/hooks/use-tambo-threads.test.js.map +0 -1
  530. package/esm/model/generate-component-response.d.ts +0 -37
  531. package/esm/model/generate-component-response.d.ts.map +0 -1
  532. package/esm/model/generate-component-response.js +0 -25
  533. package/esm/model/generate-component-response.js.map +0 -1
  534. package/esm/model/tambo-thread.d.ts +0 -15
  535. package/esm/model/tambo-thread.d.ts.map +0 -1
  536. package/esm/model/tambo-thread.js +0 -2
  537. package/esm/model/tambo-thread.js.map +0 -1
  538. package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts +0 -2
  539. package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +0 -1
  540. package/esm/providers/__tests__/thread-input-resource-resolution.test.js +0 -587
  541. package/esm/providers/__tests__/thread-input-resource-resolution.test.js.map +0 -1
  542. package/esm/providers/index.d.ts +0 -13
  543. package/esm/providers/index.d.ts.map +0 -1
  544. package/esm/providers/index.js +0 -11
  545. package/esm/providers/index.js.map +0 -1
  546. package/esm/providers/tambo-component-provider.d.ts +0 -23
  547. package/esm/providers/tambo-component-provider.d.ts.map +0 -1
  548. package/esm/providers/tambo-component-provider.js +0 -50
  549. package/esm/providers/tambo-component-provider.js.map +0 -1
  550. package/esm/providers/tambo-prop-stream-provider/index.d.ts +0 -19
  551. package/esm/providers/tambo-prop-stream-provider/index.d.ts.map +0 -1
  552. package/esm/providers/tambo-prop-stream-provider/index.js +0 -22
  553. package/esm/providers/tambo-prop-stream-provider/index.js.map +0 -1
  554. package/esm/providers/tambo-prop-stream-provider/pending.d.ts +0 -12
  555. package/esm/providers/tambo-prop-stream-provider/pending.d.ts.map +0 -1
  556. package/esm/providers/tambo-prop-stream-provider/pending.js +0 -24
  557. package/esm/providers/tambo-prop-stream-provider/pending.js.map +0 -1
  558. package/esm/providers/tambo-prop-stream-provider/provider.d.ts +0 -17
  559. package/esm/providers/tambo-prop-stream-provider/provider.d.ts.map +0 -1
  560. package/esm/providers/tambo-prop-stream-provider/provider.js +0 -70
  561. package/esm/providers/tambo-prop-stream-provider/provider.js.map +0 -1
  562. package/esm/providers/tambo-prop-stream-provider/streaming.d.ts +0 -12
  563. package/esm/providers/tambo-prop-stream-provider/streaming.d.ts.map +0 -1
  564. package/esm/providers/tambo-prop-stream-provider/streaming.js +0 -21
  565. package/esm/providers/tambo-prop-stream-provider/streaming.js.map +0 -1
  566. package/esm/providers/tambo-prop-stream-provider/success.d.ts +0 -12
  567. package/esm/providers/tambo-prop-stream-provider/success.d.ts.map +0 -1
  568. package/esm/providers/tambo-prop-stream-provider/success.js +0 -21
  569. package/esm/providers/tambo-prop-stream-provider/success.js.map +0 -1
  570. package/esm/providers/tambo-prop-stream-provider/types.d.ts +0 -25
  571. package/esm/providers/tambo-prop-stream-provider/types.d.ts.map +0 -1
  572. package/esm/providers/tambo-prop-stream-provider/types.js +0 -3
  573. package/esm/providers/tambo-prop-stream-provider/types.js.map +0 -1
  574. package/esm/providers/tambo-prop-stream-provider.test.d.ts +0 -2
  575. package/esm/providers/tambo-prop-stream-provider.test.d.ts.map +0 -1
  576. package/esm/providers/tambo-prop-stream-provider.test.js +0 -270
  577. package/esm/providers/tambo-prop-stream-provider.test.js.map +0 -1
  578. package/esm/providers/tambo-provider.d.ts +0 -53
  579. package/esm/providers/tambo-provider.d.ts.map +0 -1
  580. package/esm/providers/tambo-provider.js +0 -94
  581. package/esm/providers/tambo-provider.js.map +0 -1
  582. package/esm/providers/tambo-stubs.d.ts +0 -89
  583. package/esm/providers/tambo-stubs.d.ts.map +0 -1
  584. package/esm/providers/tambo-stubs.js +0 -242
  585. package/esm/providers/tambo-stubs.js.map +0 -1
  586. package/esm/providers/tambo-stubs.test.d.ts +0 -2
  587. package/esm/providers/tambo-stubs.test.d.ts.map +0 -1
  588. package/esm/providers/tambo-stubs.test.js +0 -62
  589. package/esm/providers/tambo-stubs.test.js.map +0 -1
  590. package/esm/providers/tambo-thread-input-provider.d.ts +0 -65
  591. package/esm/providers/tambo-thread-input-provider.d.ts.map +0 -1
  592. package/esm/providers/tambo-thread-input-provider.js +0 -141
  593. package/esm/providers/tambo-thread-input-provider.js.map +0 -1
  594. package/esm/providers/tambo-thread-provider-initial-messages.test.d.ts +0 -2
  595. package/esm/providers/tambo-thread-provider-initial-messages.test.d.ts.map +0 -1
  596. package/esm/providers/tambo-thread-provider-initial-messages.test.js +0 -273
  597. package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +0 -1
  598. package/esm/providers/tambo-thread-provider.d.ts +0 -126
  599. package/esm/providers/tambo-thread-provider.d.ts.map +0 -1
  600. package/esm/providers/tambo-thread-provider.js +0 -891
  601. package/esm/providers/tambo-thread-provider.js.map +0 -1
  602. package/esm/providers/tambo-thread-provider.test.d.ts +0 -2
  603. package/esm/providers/tambo-thread-provider.test.d.ts.map +0 -1
  604. package/esm/providers/tambo-thread-provider.test.js +0 -1553
  605. package/esm/providers/tambo-thread-provider.test.js.map +0 -1
  606. package/esm/util/generate-component.d.ts +0 -12
  607. package/esm/util/generate-component.d.ts.map +0 -1
  608. package/esm/util/generate-component.js +0 -52
  609. package/esm/util/generate-component.js.map +0 -1
  610. package/esm/util/generate-component.test.d.ts +0 -2
  611. package/esm/util/generate-component.test.d.ts.map +0 -1
  612. package/esm/util/generate-component.test.js +0 -302
  613. package/esm/util/generate-component.test.js.map +0 -1
@@ -1,891 +0,0 @@
1
- "use client";
2
- import { advanceStream } from "@tambo-ai/typescript-sdk";
3
- import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
4
- import { GenerationStage, isIdleStage, } from "../model/generate-component-response.js";
5
- import { toText } from "../util/content-parts.js";
6
- import { renderComponentIntoMessage } from "../util/generate-component.js";
7
- import { getAvailableComponents, getUnassociatedTools, mapTamboToolToContextTool, } from "../util/registry.js";
8
- import { handleToolCall } from "../util/tool-caller.js";
9
- import { useTamboClient, useTamboQueryClient } from "./tambo-client-provider.js";
10
- import { useTamboContextHelpers } from "./tambo-context-helpers-provider.js";
11
- import { useTamboRegistry } from "./tambo-registry-provider.js";
12
- const TamboGenerationStageContext = createContext(undefined);
13
- /**
14
- *
15
- * This provider is used to provide the generation stage context to the descendants of the provider.
16
- * @param props - The props for the GenerationStageProvider
17
- * @param props.children - The children to wrap
18
- * @param props.generationStage - The generation stage to provide
19
- * @param props.statusMessage - The status message to provide
20
- * @returns The GenerationStageProvider component
21
- */
22
- export const TamboGenerationStageProvider = ({ children, generationStage, statusMessage }) => {
23
- const isIdle = isIdleStage(generationStage);
24
- const contextValue = useMemo(() => {
25
- return {
26
- generationStage,
27
- generationStatusMessage: statusMessage,
28
- isIdle,
29
- };
30
- }, [generationStage, statusMessage, isIdle]);
31
- return (React.createElement(TamboGenerationStageContext.Provider, { value: contextValue }, children));
32
- };
33
- /**
34
- * This is a stub entry for when the thread is not yet created, the first time
35
- * the user sends a message
36
- *
37
- * Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,
38
- * as this doesn't really exist on the server side.
39
- */
40
- export const PLACEHOLDER_THREAD = {
41
- id: "placeholder",
42
- messages: [],
43
- createdAt: "",
44
- projectId: "",
45
- updatedAt: "",
46
- metadata: {},
47
- };
48
- export const TamboThreadContext = createContext({
49
- thread: PLACEHOLDER_THREAD,
50
- currentThreadId: PLACEHOLDER_THREAD.id,
51
- currentThread: PLACEHOLDER_THREAD,
52
- threadMap: { [PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD },
53
- setThreadMap: () => {
54
- throw new Error("setThreadMap not implemented");
55
- },
56
- /**
57
- *
58
- */
59
- switchCurrentThread: () => {
60
- throw new Error("switchCurrentThread not implemented");
61
- },
62
- /**
63
- *
64
- */
65
- startNewThread: () => {
66
- throw new Error("startNewThread not implemented");
67
- },
68
- /**
69
- *
70
- */
71
- updateThreadName: () => {
72
- throw new Error("updateThreadName not implemented");
73
- },
74
- /**
75
- *
76
- */
77
- generateThreadName: () => {
78
- throw new Error("generateThreadName not implemented");
79
- },
80
- /**
81
- *
82
- */
83
- addThreadMessage: () => {
84
- throw new Error("updateThreadMessageHistory not implemented");
85
- },
86
- streaming: true,
87
- /**
88
- *
89
- */
90
- updateThreadMessage: () => {
91
- throw new Error("updateThreadMessage not implemented");
92
- },
93
- /**
94
- *
95
- */
96
- sendThreadMessage: () => {
97
- throw new Error("sendThreadMessage not implemented");
98
- },
99
- /**
100
- *
101
- */
102
- cancel: () => {
103
- throw new Error("cancel not implemented");
104
- },
105
- });
106
- /**
107
- * The TamboThreadProvider is a React provider that provides a thread context
108
- * to the descendants of the provider.
109
- * @param props - The props for the TamboThreadProvider
110
- * @param props.children - The children to wrap
111
- * @param props.streaming - Whether to stream the response by default. Defaults to true.
112
- * @param props.initialMessages - Initial messages to be included in new threads
113
- * @param props.autoGenerateThreadName - Whether to automatically generate thread names. Defaults to true.
114
- * @param props.autoGenerateNameThreshold - The message count threshold at which the thread name will be auto-generated. Defaults to 3.
115
- * @param props.contextKey - The context key to use for thread isolation
116
- * @returns The TamboThreadProvider component
117
- */
118
- export const TamboThreadProvider = ({ children, streaming = true, initialMessages = [], autoGenerateThreadName = true, autoGenerateNameThreshold = 3, contextKey, }) => {
119
- // Create placeholder thread with initial messages
120
- const placeholderThread = useMemo(() => ({
121
- id: "placeholder",
122
- messages: initialMessages.map((msg) => ({
123
- ...msg,
124
- id: msg.id ?? crypto.randomUUID(),
125
- threadId: "placeholder",
126
- createdAt: msg.createdAt ?? new Date().toISOString(),
127
- componentState: msg.componentState ?? {},
128
- })),
129
- createdAt: "",
130
- projectId: "",
131
- updatedAt: "",
132
- metadata: {},
133
- contextKey,
134
- }), [contextKey, initialMessages]);
135
- const [threadMap, setThreadMap] = useState({
136
- [placeholderThread.id]: placeholderThread,
137
- });
138
- const client = useTamboClient();
139
- const queryClient = useTamboQueryClient();
140
- const { componentList, toolRegistry, componentToolAssociations, onCallUnregisteredTool, } = useTamboRegistry();
141
- const { getAdditionalContext } = useTamboContextHelpers();
142
- const [ignoreResponse, setIgnoreResponse] = useState(false);
143
- const ignoreResponseRef = useRef(ignoreResponse);
144
- const [currentThreadId, setCurrentThreadId] = useState(placeholderThread.id);
145
- const currentThread = threadMap[currentThreadId];
146
- // Generation stage props for GenerationStageProvider
147
- const currentGenerationStage = currentThread?.generationStage ?? GenerationStage.IDLE;
148
- const currentStatusMessage = currentThread?.statusMessage ?? "";
149
- // Use existing messages from the current thread to avoid re-generating any components
150
- const currentMessageCache = useMemo(() => {
151
- const messageCache = new Map();
152
- if (currentThread) {
153
- for (const message of currentThread.messages) {
154
- messageCache.set(message.id, message);
155
- }
156
- }
157
- return messageCache;
158
- }, [currentThread]);
159
- useEffect(() => {
160
- ignoreResponseRef.current = ignoreResponse;
161
- }, [ignoreResponse]);
162
- const updateThreadsCache = useCallback(async (updateFn, contextKey) => {
163
- try {
164
- const currentProject = await client.beta.projects.getCurrent();
165
- queryClient.setQueryData(["threads", currentProject.id, contextKey], updateFn);
166
- await queryClient.invalidateQueries({
167
- queryKey: ["threads"],
168
- });
169
- }
170
- catch (error) {
171
- console.warn("Failed to update threads cache:", error);
172
- }
173
- }, [client.beta.projects, queryClient]);
174
- const addThreadToCache = useCallback(async (threadId, contextKey) => {
175
- const optimisticThread = {
176
- ...PLACEHOLDER_THREAD,
177
- id: threadId,
178
- createdAt: new Date().toISOString(),
179
- updatedAt: new Date().toISOString(),
180
- };
181
- await updateThreadsCache((old) => {
182
- if (!old)
183
- return old;
184
- return {
185
- ...old,
186
- items: [optimisticThread, ...(old.items ?? [])],
187
- total: (old.total ?? 0) + 1,
188
- count: (old.count ?? 0) + 1,
189
- };
190
- }, contextKey);
191
- }, [updateThreadsCache]);
192
- const updateThreadInCache = useCallback(async (threadId, updateFn, contextKey) => {
193
- await updateThreadsCache((old) => {
194
- if (!old?.items)
195
- return old;
196
- return {
197
- ...old,
198
- items: old.items.map((thread) => thread.id === threadId ? updateFn(thread) : thread),
199
- total: old.total,
200
- count: old.count,
201
- };
202
- }, contextKey);
203
- }, [updateThreadsCache]);
204
- const fetchThread = useCallback(async (threadId) => {
205
- const thread = await client.beta.threads.retrieve(threadId);
206
- const threadWithRenderedComponents = {
207
- ...thread,
208
- messages: thread.messages.map((message) => {
209
- if (currentMessageCache.has(message.id)) {
210
- const renderedMessage = currentMessageCache.get(message.id);
211
- return {
212
- ...renderedMessage,
213
- ...message,
214
- };
215
- }
216
- if (message.component?.componentName) {
217
- const messageWithComponent = renderComponentIntoMessage(message, componentList);
218
- return messageWithComponent;
219
- }
220
- return message;
221
- }),
222
- };
223
- setThreadMap((prevMap) => {
224
- const updatedThreadMap = {
225
- ...prevMap,
226
- [threadId]: threadWithRenderedComponents,
227
- };
228
- return updatedThreadMap;
229
- });
230
- }, [client.beta.threads, componentList, currentMessageCache]);
231
- useEffect(() => {
232
- async function loadThread() {
233
- try {
234
- await fetchThread(currentThreadId);
235
- }
236
- catch (error) {
237
- console.error("Failed to fetch thread:", error);
238
- }
239
- }
240
- if (currentThreadId &&
241
- currentThreadId !== placeholderThread.id &&
242
- !threadMap[currentThreadId]) {
243
- loadThread().catch((err) => {
244
- console.error("Unexpected error in loadThread:", err);
245
- });
246
- }
247
- }, [currentThreadId, fetchThread, threadMap, placeholderThread.id]);
248
- const addThreadMessage = useCallback(async (message, sendToServer = true, createdAt = new Date().toISOString()) => {
249
- if (!currentThread) {
250
- console.warn("Cannot add messages if we do not have a current thread");
251
- return [];
252
- }
253
- const chatMessage = {
254
- ...message,
255
- createdAt,
256
- };
257
- const threadId = message.threadId;
258
- const messageId = chatMessage.id;
259
- // optimistically update the thread in the local state
260
- setThreadMap((prevMap) => {
261
- if (!threadId) {
262
- return prevMap;
263
- }
264
- const prevMessages = prevMap[threadId]?.messages || [];
265
- const haveMessage = prevMessages.find((msg) => msg.id === messageId);
266
- // Update in place if the message already exists
267
- const updatedMessages = haveMessage
268
- ? prevMessages.map((msg) => {
269
- if (msg.id === messageId) {
270
- return chatMessage;
271
- }
272
- return msg;
273
- })
274
- : [...prevMessages, chatMessage];
275
- const updatedThreadMap = {
276
- ...prevMap,
277
- [threadId]: {
278
- ...prevMap[threadId],
279
- messages: updatedMessages,
280
- },
281
- };
282
- return updatedThreadMap;
283
- });
284
- if (sendToServer) {
285
- try {
286
- await client.beta.threads.messages.create(message.threadId, {
287
- content: message.content,
288
- role: message.role,
289
- additionalContext: chatMessage.additionalContext,
290
- });
291
- }
292
- catch (error) {
293
- console.error("Failed to add message to server", error);
294
- // Revert optimistic local state update
295
- setThreadMap((prev) => {
296
- const prevMessages = prev[threadId]?.messages || [];
297
- // addThreadMessage -> for new messages or simple updates
298
- // On Fail -> remove the added/updated message (no prev state)
299
- const updatedMessages = prevMessages.filter((msg) => msg.id !== messageId);
300
- return {
301
- ...prev,
302
- [threadId]: {
303
- ...prev[threadId],
304
- messages: updatedMessages,
305
- },
306
- };
307
- });
308
- throw error;
309
- }
310
- }
311
- return threadMap[threadId]?.messages || [];
312
- }, [client.beta.threads.messages, currentThread, threadMap]);
313
- const updateThreadMessage = useCallback(async (id, message, sendToServer = true, createdAt = new Date().toISOString()) => {
314
- setThreadMap((prevMap) => {
315
- const prevMessages = prevMap[message.threadId]?.messages || [];
316
- const updatedMessages = prevMessages.map((msg) => {
317
- if (msg.id === id) {
318
- // Merge the partial update with the existing message
319
- const updatedMessage = {
320
- ...msg,
321
- ...message,
322
- id: msg.id,
323
- createdAt: message.createdAt ?? msg.createdAt ?? createdAt,
324
- };
325
- return updatedMessage;
326
- }
327
- return msg;
328
- });
329
- return {
330
- ...prevMap,
331
- [message.threadId]: {
332
- ...prevMap[message.threadId],
333
- messages: updatedMessages,
334
- },
335
- };
336
- });
337
- if (sendToServer && message.content && message.role) {
338
- try {
339
- await client.beta.threads.messages.create(message.threadId, {
340
- content: message.content,
341
- role: message.role,
342
- additionalContext: message.additionalContext,
343
- });
344
- }
345
- catch (error) {
346
- console.error("Failed to update message on server", error);
347
- // Revert local state update by removing the optimistic message
348
- setThreadMap((prev) => {
349
- const updatedMessages = prev[message.threadId]?.messages?.filter((msg) => msg.id !== id);
350
- return {
351
- ...prev,
352
- [message.threadId]: {
353
- ...prev[message.threadId],
354
- messages: updatedMessages,
355
- },
356
- };
357
- });
358
- throw error;
359
- }
360
- }
361
- }, [client.beta.threads.messages]);
362
- const generateThreadName = useCallback(async (threadId, contextKey) => {
363
- threadId ??= currentThreadId;
364
- if (threadId === placeholderThread.id) {
365
- console.warn("Cannot generate name for empty thread");
366
- return threadMap[threadId];
367
- }
368
- const threadWithGeneratedName = await client.beta.threads.generateName(threadId);
369
- // Update local thread state
370
- setThreadMap((prevMap) => {
371
- if (!prevMap[threadId]) {
372
- return prevMap;
373
- }
374
- return {
375
- ...prevMap,
376
- [threadId]: {
377
- ...prevMap[threadId],
378
- name: threadWithGeneratedName.name,
379
- },
380
- };
381
- });
382
- // Update threads cache to reflect the new name in the UI
383
- await updateThreadInCache(threadId, (thread) => ({
384
- ...thread,
385
- name: threadWithGeneratedName.name,
386
- }), contextKey);
387
- return threadWithGeneratedName;
388
- }, [
389
- client.beta.threads,
390
- currentThreadId,
391
- threadMap,
392
- placeholderThread.id,
393
- updateThreadInCache,
394
- ]);
395
- const maybeAutoGenerateThreadName = useCallback((threadId, contextKey) => {
396
- // Use setThreadMap to access the latest state
397
- setThreadMap((map) => {
398
- const thread = map[threadId];
399
- if (!thread || !autoGenerateThreadName) {
400
- return map;
401
- }
402
- if (autoGenerateNameThreshold == null ||
403
- thread.id === placeholderThread.id) {
404
- return map;
405
- }
406
- const messageCount = thread.messages.length;
407
- // Only auto-generate if thread has no name and threshold is met
408
- if (!thread.name && messageCount >= autoGenerateNameThreshold) {
409
- // Generating a thread name is not critical, so we can fire-and-forget
410
- void generateThreadName(threadId, contextKey).catch((error) => {
411
- console.error("Failed to generate thread name:", error);
412
- });
413
- }
414
- return map;
415
- });
416
- }, [
417
- autoGenerateThreadName,
418
- autoGenerateNameThreshold,
419
- placeholderThread.id,
420
- generateThreadName,
421
- ]);
422
- const startNewThread = useCallback(() => {
423
- setCurrentThreadId(placeholderThread.id);
424
- setThreadMap((prevMap) => {
425
- return {
426
- ...prevMap,
427
- [placeholderThread.id]: placeholderThread,
428
- };
429
- });
430
- }, [placeholderThread]);
431
- const updateThreadName = useCallback(async (name, threadId) => {
432
- threadId ??= currentThreadId;
433
- const previousName = threadMap[threadId]?.name;
434
- setThreadMap((prevMap) => {
435
- if (!prevMap[threadId]) {
436
- return prevMap;
437
- }
438
- return { ...prevMap, [threadId]: { ...prevMap[threadId], name } };
439
- });
440
- if (threadId !== placeholderThread.id) {
441
- try {
442
- const currentProject = await client.beta.projects.getCurrent();
443
- await client.beta.threads.update(threadId, {
444
- name,
445
- projectId: currentProject.id,
446
- });
447
- }
448
- catch (error) {
449
- console.error("Failed to update thread name on server", error);
450
- // Revert local state update
451
- setThreadMap((prevMap) => {
452
- if (!prevMap[threadId]) {
453
- return prevMap;
454
- }
455
- return {
456
- ...prevMap,
457
- [threadId]: { ...prevMap[threadId], name: previousName },
458
- };
459
- });
460
- throw error;
461
- }
462
- }
463
- }, [
464
- currentThreadId,
465
- client.beta.projects,
466
- client.beta.threads,
467
- placeholderThread.id,
468
- threadMap,
469
- ]);
470
- const switchCurrentThread = useCallback(async (threadId, fetch = true) => {
471
- if (threadId === placeholderThread.id) {
472
- console.warn("Switching to placeholder thread, may be a bug.");
473
- return;
474
- }
475
- setCurrentThreadId(threadId);
476
- setThreadMap((prevMap) => {
477
- if (prevMap[threadId]) {
478
- return prevMap;
479
- }
480
- // If this is a new thread, add placeholder thread messages to the thread
481
- const updatedThreadMap = {
482
- ...prevMap,
483
- [threadId]: {
484
- ...prevMap[placeholderThread.id],
485
- id: threadId,
486
- },
487
- };
488
- return updatedThreadMap;
489
- });
490
- if (fetch) {
491
- await fetchThread(threadId);
492
- }
493
- }, [fetchThread, placeholderThread]);
494
- const updateThreadStatus = useCallback((threadId, stage, statusMessage) => {
495
- setThreadMap((prevMap) => {
496
- const updatedThreadMap = {
497
- ...prevMap,
498
- [threadId]: {
499
- ...prevMap[threadId],
500
- generationStage: stage,
501
- statusMessage: statusMessage,
502
- },
503
- };
504
- return updatedThreadMap;
505
- });
506
- }, []);
507
- const cancel = useCallback(async (threadId) => {
508
- threadId ??= currentThreadId;
509
- const currentGenerationStage = currentThread?.generationStage ?? GenerationStage.IDLE;
510
- if (isIdleStage(currentGenerationStage)) {
511
- return;
512
- }
513
- setIgnoreResponse(true);
514
- setThreadMap((prevMap) => {
515
- if (!prevMap[threadId]) {
516
- return prevMap;
517
- }
518
- return {
519
- ...prevMap,
520
- [threadId]: {
521
- ...prevMap[threadId],
522
- generationStage: GenerationStage.CANCELLED,
523
- messages: prevMap[threadId].messages.map((message) => {
524
- if (message.id ===
525
- prevMap[threadId].messages[prevMap[threadId].messages.length - 1].id) {
526
- return {
527
- ...message,
528
- isCancelled: true,
529
- };
530
- }
531
- return message;
532
- }),
533
- },
534
- };
535
- });
536
- await client.beta.threads.cancel(threadId);
537
- }, [client.beta.threads, currentThreadId, currentThread?.generationStage]);
538
- const handleAdvanceStream = useCallback(async (stream, params, threadId, contextKey) => {
539
- if (ignoreResponseRef.current) {
540
- setIgnoreResponse(false);
541
- return createEmptyMessage(threadId);
542
- }
543
- let finalMessage;
544
- let hasSetThreadId = false;
545
- updateThreadStatus(threadId, GenerationStage.STREAMING_RESPONSE);
546
- for await (const chunk of stream) {
547
- // Store MCP access token in thread data
548
- if (chunk.mcpAccessToken) {
549
- // note that we're only setting it positively during streaming, because it might
550
- // not have been set yet in the chunk (i.e. we're not unsetting it in the chunk)
551
- setThreadMap((prev) => {
552
- const thread = prev[threadId];
553
- if (thread) {
554
- return {
555
- ...prev,
556
- [threadId]: {
557
- ...thread,
558
- mcpAccessToken: chunk.mcpAccessToken,
559
- },
560
- };
561
- }
562
- return prev;
563
- });
564
- }
565
- if (chunk.responseMessageDto.toolCallRequest) {
566
- const toolName = chunk.responseMessageDto.toolCallRequest.toolName;
567
- updateThreadStatus(chunk.responseMessageDto.threadId, GenerationStage.FETCHING_CONTEXT);
568
- await updateThreadMessage(chunk.responseMessageDto.id, {
569
- ...chunk.responseMessageDto,
570
- }, false);
571
- const toolCallResponse = await handleToolCall(chunk.responseMessageDto.toolCallRequest, toolRegistry, onCallUnregisteredTool);
572
- if (ignoreResponseRef.current) {
573
- setIgnoreResponse(false);
574
- return createEmptyMessage(threadId);
575
- }
576
- const contentParts = await convertToolResponse(toolCallResponse);
577
- const toolCallResponseParams = {
578
- ...params,
579
- // Exclude initialMessages from tool response since thread already exists
580
- initialMessages: undefined,
581
- ...(toolName
582
- ? {
583
- toolCallCounts: {
584
- ...(params.toolCallCounts ?? {}),
585
- [toolName]: (params.toolCallCounts?.[toolName] ?? 0) + 1,
586
- },
587
- }
588
- : {}),
589
- messageToAppend: {
590
- content: contentParts,
591
- role: "tool",
592
- actionType: "tool_response",
593
- component: chunk.responseMessageDto.component,
594
- tool_call_id: chunk.responseMessageDto.tool_call_id,
595
- error: toolCallResponse.error,
596
- },
597
- };
598
- await updateThreadMessage(chunk.responseMessageDto.id, {
599
- ...chunk.responseMessageDto,
600
- error: toolCallResponse.error,
601
- }, false);
602
- await addThreadMessage({
603
- threadId: chunk.responseMessageDto.threadId,
604
- content: contentParts,
605
- role: "tool",
606
- id: crypto.randomUUID(),
607
- createdAt: new Date().toISOString(),
608
- componentState: {},
609
- actionType: "tool_response",
610
- tool_call_id: chunk.responseMessageDto.tool_call_id,
611
- error: toolCallResponse.error,
612
- }, false);
613
- updateThreadStatus(chunk.responseMessageDto.threadId, GenerationStage.STREAMING_RESPONSE);
614
- const toolCallResponseStream = await advanceStream(client, toolCallResponseParams, chunk.responseMessageDto.threadId);
615
- return await handleAdvanceStream(toolCallResponseStream, toolCallResponseParams, chunk.responseMessageDto.threadId, contextKey);
616
- }
617
- else {
618
- if (ignoreResponseRef.current) {
619
- setIgnoreResponse(false);
620
- return finalMessage ?? createEmptyMessage(threadId);
621
- }
622
- if (!hasSetThreadId &&
623
- chunk.responseMessageDto.threadId &&
624
- chunk.responseMessageDto.threadId !== currentThread?.id) {
625
- hasSetThreadId = true;
626
- const wasPlaceholderThread = currentThreadId === PLACEHOLDER_THREAD.id;
627
- await switchCurrentThread(chunk.responseMessageDto.threadId, false);
628
- // If we're switching from placeholder to a real thread
629
- // this means a new thread was created, so add it to cache
630
- if (wasPlaceholderThread) {
631
- await addThreadToCache(chunk.responseMessageDto.threadId, contextKey);
632
- // Check if we should auto-generate name for the newly created thread
633
- maybeAutoGenerateThreadName(chunk.responseMessageDto.threadId, contextKey);
634
- }
635
- }
636
- if (!finalMessage) {
637
- finalMessage = chunk.responseMessageDto.component?.componentName
638
- ? renderComponentIntoMessage(chunk.responseMessageDto, componentList)
639
- : chunk.responseMessageDto;
640
- await addThreadMessage(finalMessage, false);
641
- }
642
- else {
643
- // Handle streaming tool calls
644
- if (chunk.responseMessageDto.component?.toolCallRequest) {
645
- const { toolName } = chunk.responseMessageDto.component.toolCallRequest;
646
- const tool = toolName ? toolRegistry[toolName] : undefined;
647
- // if there is a tool call request on a component in a streaming chunk, and the tool
648
- // is marked as streamable by the correct annotation, handle it
649
- const isStreamable = tool?.annotations?.tamboStreamableHint ?? false;
650
- if (isStreamable) {
651
- // We're not paying attention to the tool call response here - we only want the
652
- // final tool call which is handled by the presence of a toolCallRequest on the
653
- // top-level responseMessageDto
654
- // see above: `if (chunk.responseMessageDto.toolCallRequest) { ... }`
655
- void (await handleToolCall(chunk.responseMessageDto.component.toolCallRequest, toolRegistry, onCallUnregisteredTool));
656
- }
657
- }
658
- // Capture previous message ID before updating finalMessage
659
- const previousMessageId = finalMessage.id;
660
- if (chunk.responseMessageDto.component?.componentName) {
661
- finalMessage = renderComponentIntoMessage(chunk.responseMessageDto, componentList);
662
- }
663
- else {
664
- finalMessage = chunk.responseMessageDto;
665
- }
666
- // if we start getting a new message mid-stream, put the previous one on screen
667
- const isNewMessage = chunk.responseMessageDto.id !== previousMessageId;
668
- if (isNewMessage) {
669
- await addThreadMessage(finalMessage, false);
670
- }
671
- else {
672
- await updateThreadMessage(finalMessage.id, finalMessage, false);
673
- }
674
- }
675
- }
676
- }
677
- const completedThreadId = finalMessage?.threadId ?? threadId;
678
- updateThreadStatus(completedThreadId, GenerationStage.COMPLETE);
679
- maybeAutoGenerateThreadName(completedThreadId, contextKey);
680
- return (finalMessage ?? {
681
- ...createEmptyMessage(completedThreadId),
682
- content: [{ type: "text", text: "Error processing stream" }],
683
- });
684
- }, [
685
- addThreadMessage,
686
- addThreadToCache,
687
- maybeAutoGenerateThreadName,
688
- client,
689
- componentList,
690
- currentThread?.id,
691
- currentThreadId,
692
- onCallUnregisteredTool,
693
- switchCurrentThread,
694
- toolRegistry,
695
- updateThreadMessage,
696
- updateThreadStatus,
697
- ]);
698
- const sendThreadMessage = useCallback(async (message, options = {}) => {
699
- setIgnoreResponse(false);
700
- const { threadId = currentThreadId ?? placeholderThread.id, streamResponse = streaming, forceToolChoice, contextKey, additionalContext, content, } = options;
701
- if (!streamResponse) {
702
- throw new Error("Non-streaming mode is deprecated. Use streaming mode instead.");
703
- }
704
- updateThreadStatus(threadId, GenerationStage.FETCHING_CONTEXT);
705
- // Get additional context from enabled helpers
706
- const helperContexts = await getAdditionalContext();
707
- // Combine all contexts
708
- const combinedContext = {
709
- ...(additionalContext ?? {}),
710
- };
711
- // Add helper contexts to combinedContext
712
- for (const helperContext of helperContexts) {
713
- combinedContext[helperContext.name] = helperContext.context;
714
- }
715
- // Build and optimistically add user message (for revert on fail)
716
- const optimiticMessageId = crypto.randomUUID();
717
- const messageContent = content ?? [
718
- { type: "text", text: message },
719
- ];
720
- await addThreadMessage({
721
- content: messageContent,
722
- renderedComponent: null,
723
- role: "user",
724
- threadId: threadId,
725
- id: optimiticMessageId,
726
- createdAt: new Date().toISOString(),
727
- componentState: {},
728
- additionalContext: combinedContext,
729
- }, false);
730
- maybeAutoGenerateThreadName(threadId, contextKey);
731
- const availableComponents = getAvailableComponents(componentList, toolRegistry, componentToolAssociations);
732
- const unassociatedTools = getUnassociatedTools(toolRegistry, componentToolAssociations);
733
- // Track tool call counts for this message processing
734
- const toolCallCounts = {};
735
- const params = {
736
- messageToAppend: {
737
- content: messageContent,
738
- role: "user",
739
- additionalContext: combinedContext,
740
- },
741
- contextKey,
742
- availableComponents: availableComponents,
743
- clientTools: unassociatedTools.map((tool) => mapTamboToolToContextTool(tool)),
744
- forceToolChoice: forceToolChoice,
745
- toolCallCounts,
746
- ...(threadId === placeholderThread.id &&
747
- initialMessages.length > 0 && {
748
- initialMessages: initialMessages.map((msg) => ({
749
- content: msg.content,
750
- role: msg.role,
751
- additionalContext: msg.additionalContext,
752
- })),
753
- }),
754
- };
755
- let advanceStreamResponse;
756
- try {
757
- advanceStreamResponse = await advanceStream(client, params, threadId === placeholderThread.id ? undefined : threadId);
758
- }
759
- catch (error) {
760
- updateThreadStatus(threadId, GenerationStage.ERROR);
761
- // Rollback the optimistic user message
762
- setThreadMap((prev) => {
763
- const thread = prev[threadId];
764
- if (!thread)
765
- return prev;
766
- return {
767
- ...prev,
768
- [threadId]: {
769
- ...thread,
770
- messages: thread.messages.filter((msg) => msg.id !== optimiticMessageId),
771
- },
772
- };
773
- });
774
- throw error;
775
- }
776
- try {
777
- const result = await handleAdvanceStream(advanceStreamResponse, params, threadId, contextKey);
778
- return result;
779
- }
780
- catch (error) {
781
- updateThreadStatus(threadId, GenerationStage.ERROR);
782
- // Rollback the optimistic user message
783
- setThreadMap((prev) => {
784
- const thread = prev[threadId];
785
- if (!thread)
786
- return prev;
787
- return {
788
- ...prev,
789
- [threadId]: {
790
- ...thread,
791
- messages: thread.messages.filter((msg) => msg.id !== optimiticMessageId),
792
- },
793
- };
794
- });
795
- throw error;
796
- }
797
- }, [
798
- componentList,
799
- toolRegistry,
800
- componentToolAssociations,
801
- currentThreadId,
802
- addThreadMessage,
803
- client,
804
- updateThreadStatus,
805
- handleAdvanceStream,
806
- streaming,
807
- getAdditionalContext,
808
- placeholderThread.id,
809
- initialMessages,
810
- maybeAutoGenerateThreadName,
811
- ]);
812
- return (React.createElement(TamboThreadContext.Provider, { value: {
813
- thread: currentThread,
814
- currentThreadId,
815
- currentThread,
816
- threadMap,
817
- setThreadMap,
818
- switchCurrentThread,
819
- startNewThread,
820
- updateThreadName,
821
- generateThreadName,
822
- addThreadMessage,
823
- updateThreadMessage,
824
- streaming,
825
- cancel,
826
- sendThreadMessage,
827
- contextKey,
828
- } },
829
- React.createElement(TamboGenerationStageProvider, { generationStage: currentGenerationStage, statusMessage: currentStatusMessage }, children)));
830
- };
831
- /**
832
- * The useTamboGenerationStage hook provides access to the generation stage context
833
- * to the descendants of the TamboThreadProvider.
834
- * @returns The generation stage context
835
- */
836
- export const useTamboGenerationStage = () => {
837
- const generationStageContext = useContext(TamboGenerationStageContext);
838
- if (generationStageContext === undefined) {
839
- throw new Error("useTamboGenerationStage must be used within a TamboThreadProvider");
840
- }
841
- return generationStageContext;
842
- };
843
- /**
844
- * The useTamboThread hook provides access to the current thread context
845
- * to the descendants of the TamboThreadProvider.
846
- * @returns All state and actions for the current thread
847
- */
848
- export const useTamboThread = () => {
849
- const threadContext = useContext(TamboThreadContext);
850
- const generationStageContext = useContext(TamboGenerationStageContext);
851
- if (threadContext === undefined) {
852
- throw new Error("useTamboThread must be used within a TamboThreadProvider");
853
- }
854
- if (generationStageContext === undefined) {
855
- throw new Error("useTamboThread must be used within a TamboThreadProvider");
856
- }
857
- return {
858
- ...threadContext,
859
- ...generationStageContext,
860
- };
861
- };
862
- async function convertToolResponse(toolCallResponse) {
863
- // If the tool call errored, surface that as text so the model reliably sees the error
864
- if (toolCallResponse.error) {
865
- return [{ type: "text", text: toText(toolCallResponse.result) }];
866
- }
867
- // Use custom transform when available
868
- if (toolCallResponse.tamboTool?.transformToContent) {
869
- return await toolCallResponse.tamboTool.transformToContent(
870
- // result shape is user-defined; let the transform decide how to handle it
871
- toolCallResponse.result);
872
- }
873
- // Default fallback to stringified text
874
- return [{ type: "text", text: toText(toolCallResponse.result) }];
875
- }
876
- /**
877
- * Create a placeholder/cancelled message with default values
878
- * @param threadId - ID of the thread the message belongs to
879
- * @returns An empty TamboThreadMessage
880
- */
881
- function createEmptyMessage(threadId) {
882
- return {
883
- threadId,
884
- content: [{ type: "text", text: "" }],
885
- role: "assistant",
886
- createdAt: new Date().toISOString(),
887
- id: crypto.randomUUID(),
888
- componentState: {},
889
- };
890
- }
891
- //# sourceMappingURL=tambo-thread-provider.js.map