@tambo-ai/react 0.67.1 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (424) hide show
  1. package/README.md +3 -5
  2. package/dist/context-helpers/context-helpers.test.js +16 -4
  3. package/dist/context-helpers/context-helpers.test.js.map +1 -1
  4. package/dist/context-helpers/current-interactables-context-helper.d.ts +2 -2
  5. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  6. package/dist/context-helpers/current-interactables-context-helper.js +31 -12
  7. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
  8. package/dist/context-helpers/registry.d.ts +2 -2
  9. package/dist/context-helpers/registry.d.ts.map +1 -1
  10. package/dist/context-helpers/registry.js.map +1 -1
  11. package/dist/context-helpers/types.d.ts +2 -2
  12. package/dist/context-helpers/types.d.ts.map +1 -1
  13. package/dist/context-helpers/types.js.map +1 -1
  14. package/dist/hoc/with-tambo-interactable.d.ts +50 -4
  15. package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
  16. package/dist/hoc/with-tambo-interactable.js +20 -5
  17. package/dist/hoc/with-tambo-interactable.js.map +1 -1
  18. package/dist/hooks/use-component-state.d.ts +3 -8
  19. package/dist/hooks/use-component-state.d.ts.map +1 -1
  20. package/dist/hooks/use-component-state.js +8 -0
  21. package/dist/hooks/use-component-state.js.map +1 -1
  22. package/dist/hooks/use-component-state.test.js +37 -0
  23. package/dist/hooks/use-component-state.test.js.map +1 -1
  24. package/dist/hooks/use-message-images.test.js +174 -37
  25. package/dist/hooks/use-message-images.test.js.map +1 -1
  26. package/dist/hooks/use-tambo-threads.js +1 -1
  27. package/dist/hooks/use-tambo-threads.js.map +1 -1
  28. package/dist/hooks/use-tambo-voice.d.ts +1 -1
  29. package/dist/hooks/use-tambo-voice.js +1 -1
  30. package/dist/hooks/use-tambo-voice.js.map +1 -1
  31. package/dist/hooks/use-tambo-voice.test.d.ts +2 -0
  32. package/dist/hooks/use-tambo-voice.test.d.ts.map +1 -0
  33. package/dist/hooks/use-tambo-voice.test.js +239 -0
  34. package/dist/hooks/use-tambo-voice.test.js.map +1 -0
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/mcp/elicitation.d.ts.map +1 -1
  39. package/dist/mcp/elicitation.js +12 -0
  40. package/dist/mcp/elicitation.js.map +1 -1
  41. package/dist/mcp/elicitation.test.js +8 -1
  42. package/dist/mcp/elicitation.test.js.map +1 -1
  43. package/dist/mcp/mcp-client.d.ts +6 -10
  44. package/dist/mcp/mcp-client.d.ts.map +1 -1
  45. package/dist/mcp/mcp-client.js.map +1 -1
  46. package/dist/mcp/mcp-constants.d.ts +19 -0
  47. package/dist/mcp/mcp-constants.d.ts.map +1 -0
  48. package/dist/mcp/mcp-constants.js +21 -0
  49. package/dist/mcp/mcp-constants.js.map +1 -0
  50. package/dist/mcp/mcp-hooks.d.ts +21 -40
  51. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  52. package/dist/mcp/mcp-hooks.js +130 -39
  53. package/dist/mcp/mcp-hooks.js.map +1 -1
  54. package/dist/mcp/mcp-hooks.test.js +431 -5
  55. package/dist/mcp/mcp-hooks.test.js.map +1 -1
  56. package/dist/mcp/tambo-mcp-provider.d.ts +7 -0
  57. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  58. package/dist/mcp/tambo-mcp-provider.js +205 -155
  59. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  60. package/dist/mcp/tambo-mcp-provider.test.js +37 -0
  61. package/dist/mcp/tambo-mcp-provider.test.js.map +1 -1
  62. package/dist/model/component-metadata.d.ts +54 -21
  63. package/dist/model/component-metadata.d.ts.map +1 -1
  64. package/dist/model/component-metadata.js.map +1 -1
  65. package/dist/model/tambo-interactable.d.ts +13 -5
  66. package/dist/model/tambo-interactable.d.ts.map +1 -1
  67. package/dist/model/tambo-interactable.js.map +1 -1
  68. package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts +2 -0
  69. package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +1 -0
  70. package/dist/providers/__tests__/thread-input-resource-resolution.test.js +592 -0
  71. package/dist/providers/__tests__/thread-input-resource-resolution.test.js.map +1 -0
  72. package/dist/providers/index.d.ts +1 -1
  73. package/dist/providers/index.d.ts.map +1 -1
  74. package/dist/providers/index.js.map +1 -1
  75. package/dist/providers/tambo-client-provider.d.ts +8 -0
  76. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  77. package/dist/providers/tambo-client-provider.js +10 -11
  78. package/dist/providers/tambo-client-provider.js.map +1 -1
  79. package/dist/providers/tambo-client-provider.test.d.ts +2 -0
  80. package/dist/providers/tambo-client-provider.test.d.ts.map +1 -0
  81. package/dist/providers/tambo-client-provider.test.js +208 -0
  82. package/dist/providers/tambo-client-provider.test.js.map +1 -0
  83. package/dist/providers/tambo-context-attachment-provider.d.ts +34 -92
  84. package/dist/providers/tambo-context-attachment-provider.d.ts.map +1 -1
  85. package/dist/providers/tambo-context-attachment-provider.js +62 -105
  86. package/dist/providers/tambo-context-attachment-provider.js.map +1 -1
  87. package/dist/providers/tambo-context-attachment-provider.test.js +229 -463
  88. package/dist/providers/tambo-context-attachment-provider.test.js.map +1 -1
  89. package/dist/providers/tambo-interactable-provider-partial-updates.test.js +22 -21
  90. package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  91. package/dist/providers/tambo-interactable-provider.d.ts +5 -2
  92. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  93. package/dist/providers/tambo-interactable-provider.js +126 -17
  94. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  95. package/dist/providers/tambo-interactable-provider.test.js +242 -0
  96. package/dist/providers/tambo-interactable-provider.test.js.map +1 -1
  97. package/dist/providers/tambo-interactables-additional-context.test.js +2 -5
  98. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  99. package/dist/providers/tambo-provider.d.ts +2 -3
  100. package/dist/providers/tambo-provider.d.ts.map +1 -1
  101. package/dist/providers/tambo-provider.js +6 -5
  102. package/dist/providers/tambo-provider.js.map +1 -1
  103. package/dist/providers/tambo-registry-provider.test.js +16 -0
  104. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  105. package/dist/providers/tambo-registry-schema-compat.test.js +31 -0
  106. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  107. package/dist/providers/tambo-thread-input-provider.d.ts +1 -1
  108. package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
  109. package/dist/providers/tambo-thread-input-provider.js +26 -4
  110. package/dist/providers/tambo-thread-input-provider.js.map +1 -1
  111. package/dist/providers/tambo-thread-provider-initial-messages.test.js +84 -2
  112. package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  113. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  114. package/dist/providers/tambo-thread-provider.js +53 -42
  115. package/dist/providers/tambo-thread-provider.js.map +1 -1
  116. package/dist/providers/tambo-thread-provider.test.js +368 -262
  117. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  118. package/dist/schema/index.d.ts +1 -1
  119. package/dist/schema/index.d.ts.map +1 -1
  120. package/dist/schema/index.js +2 -1
  121. package/dist/schema/index.js.map +1 -1
  122. package/dist/schema/json-schema.d.ts +7 -0
  123. package/dist/schema/json-schema.d.ts.map +1 -1
  124. package/dist/schema/json-schema.js +40 -29
  125. package/dist/schema/json-schema.js.map +1 -1
  126. package/dist/schema/json-schema.test.d.ts +2 -0
  127. package/dist/schema/json-schema.test.d.ts.map +1 -0
  128. package/dist/schema/json-schema.test.js +204 -0
  129. package/dist/schema/json-schema.test.js.map +1 -0
  130. package/dist/schema/schema.test.js +237 -0
  131. package/dist/schema/schema.test.js.map +1 -1
  132. package/dist/schema/standard-schema.d.ts +1 -0
  133. package/dist/schema/standard-schema.d.ts.map +1 -1
  134. package/dist/schema/standard-schema.js +18 -13
  135. package/dist/schema/standard-schema.js.map +1 -1
  136. package/dist/schema/standard-schema.test.d.ts +2 -0
  137. package/dist/schema/standard-schema.test.d.ts.map +1 -0
  138. package/dist/schema/standard-schema.test.js +165 -0
  139. package/dist/schema/standard-schema.test.js.map +1 -0
  140. package/dist/schema/validate.test.js +149 -0
  141. package/dist/schema/validate.test.js.map +1 -1
  142. package/dist/schema/zod.d.ts +7 -4
  143. package/dist/schema/zod.d.ts.map +1 -1
  144. package/dist/schema/zod.js +65 -22
  145. package/dist/schema/zod.js.map +1 -1
  146. package/dist/schema/zod.test.js +112 -0
  147. package/dist/schema/zod.test.js.map +1 -1
  148. package/dist/setupTests.js +3 -0
  149. package/dist/setupTests.js.map +1 -1
  150. package/dist/testing/tools.d.ts +4 -1
  151. package/dist/testing/tools.d.ts.map +1 -1
  152. package/dist/testing/tools.js +6 -1
  153. package/dist/testing/tools.js.map +1 -1
  154. package/dist/util/generate-component.d.ts.map +1 -1
  155. package/dist/util/generate-component.js +18 -3
  156. package/dist/util/generate-component.js.map +1 -1
  157. package/dist/util/generate-component.test.d.ts +2 -0
  158. package/dist/util/generate-component.test.d.ts.map +1 -0
  159. package/dist/util/generate-component.test.js +340 -0
  160. package/dist/util/generate-component.test.js.map +1 -0
  161. package/dist/util/is-promise.d.ts +9 -0
  162. package/dist/util/is-promise.d.ts.map +1 -0
  163. package/dist/util/is-promise.js +20 -0
  164. package/dist/util/is-promise.js.map +1 -0
  165. package/dist/util/is-promise.test.d.ts +2 -0
  166. package/dist/util/is-promise.test.d.ts.map +1 -0
  167. package/dist/util/is-promise.test.js +48 -0
  168. package/dist/util/is-promise.test.js.map +1 -0
  169. package/dist/util/message-builder.d.ts +3 -1
  170. package/dist/util/message-builder.d.ts.map +1 -1
  171. package/dist/util/message-builder.js +20 -3
  172. package/dist/util/message-builder.js.map +1 -1
  173. package/dist/util/message-builder.test.js +269 -0
  174. package/dist/util/message-builder.test.js.map +1 -1
  175. package/dist/util/query-utils.test.d.ts +2 -0
  176. package/dist/util/query-utils.test.d.ts.map +1 -0
  177. package/dist/util/query-utils.test.js +382 -0
  178. package/dist/util/query-utils.test.js.map +1 -0
  179. package/dist/util/registry-validators.d.ts.map +1 -1
  180. package/dist/util/registry-validators.js +7 -0
  181. package/dist/util/registry-validators.js.map +1 -1
  182. package/dist/util/registry-validators.test.js +57 -0
  183. package/dist/util/registry-validators.test.js.map +1 -1
  184. package/dist/util/registry.d.ts.map +1 -1
  185. package/dist/util/registry.js +9 -0
  186. package/dist/util/registry.js.map +1 -1
  187. package/dist/util/registry.test.js +323 -1
  188. package/dist/util/registry.test.js.map +1 -1
  189. package/dist/util/resource-content-resolver.d.ts +20 -0
  190. package/dist/util/resource-content-resolver.d.ts.map +1 -0
  191. package/dist/util/resource-content-resolver.js +93 -0
  192. package/dist/util/resource-content-resolver.js.map +1 -0
  193. package/dist/util/resource-content-resolver.test.d.ts +2 -0
  194. package/dist/util/resource-content-resolver.test.d.ts.map +1 -0
  195. package/dist/util/resource-content-resolver.test.js +254 -0
  196. package/dist/util/resource-content-resolver.test.js.map +1 -0
  197. package/dist/util/resource-validators.test.d.ts +2 -0
  198. package/dist/util/resource-validators.test.d.ts.map +1 -0
  199. package/dist/util/resource-validators.test.js +90 -0
  200. package/dist/util/resource-validators.test.js.map +1 -0
  201. package/dist/util/tool-caller.d.ts +2 -2
  202. package/dist/util/tool-caller.d.ts.map +1 -1
  203. package/dist/util/tool-caller.js +8 -8
  204. package/dist/util/tool-caller.js.map +1 -1
  205. package/dist/util/validate-component-name.test.d.ts +2 -0
  206. package/dist/util/validate-component-name.test.d.ts.map +1 -0
  207. package/dist/util/validate-component-name.test.js +35 -0
  208. package/dist/util/validate-component-name.test.js.map +1 -0
  209. package/esm/context-helpers/context-helpers.test.js +16 -4
  210. package/esm/context-helpers/context-helpers.test.js.map +1 -1
  211. package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
  212. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  213. package/esm/context-helpers/current-interactables-context-helper.js +31 -12
  214. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  215. package/esm/context-helpers/registry.d.ts +2 -2
  216. package/esm/context-helpers/registry.d.ts.map +1 -1
  217. package/esm/context-helpers/registry.js.map +1 -1
  218. package/esm/context-helpers/types.d.ts +2 -2
  219. package/esm/context-helpers/types.d.ts.map +1 -1
  220. package/esm/context-helpers/types.js.map +1 -1
  221. package/esm/hoc/with-tambo-interactable.d.ts +50 -4
  222. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
  223. package/esm/hoc/with-tambo-interactable.js +20 -5
  224. package/esm/hoc/with-tambo-interactable.js.map +1 -1
  225. package/esm/hooks/use-component-state.d.ts +3 -8
  226. package/esm/hooks/use-component-state.d.ts.map +1 -1
  227. package/esm/hooks/use-component-state.js +8 -0
  228. package/esm/hooks/use-component-state.js.map +1 -1
  229. package/esm/hooks/use-component-state.test.js +37 -0
  230. package/esm/hooks/use-component-state.test.js.map +1 -1
  231. package/esm/hooks/use-message-images.test.js +174 -37
  232. package/esm/hooks/use-message-images.test.js.map +1 -1
  233. package/esm/hooks/use-tambo-threads.js +1 -1
  234. package/esm/hooks/use-tambo-threads.js.map +1 -1
  235. package/esm/hooks/use-tambo-voice.d.ts +1 -1
  236. package/esm/hooks/use-tambo-voice.js +1 -1
  237. package/esm/hooks/use-tambo-voice.js.map +1 -1
  238. package/esm/hooks/use-tambo-voice.test.d.ts +2 -0
  239. package/esm/hooks/use-tambo-voice.test.d.ts.map +1 -0
  240. package/esm/hooks/use-tambo-voice.test.js +234 -0
  241. package/esm/hooks/use-tambo-voice.test.js.map +1 -0
  242. package/esm/index.d.ts +2 -2
  243. package/esm/index.d.ts.map +1 -1
  244. package/esm/index.js.map +1 -1
  245. package/esm/mcp/elicitation.d.ts.map +1 -1
  246. package/esm/mcp/elicitation.js +12 -0
  247. package/esm/mcp/elicitation.js.map +1 -1
  248. package/esm/mcp/elicitation.test.js +8 -1
  249. package/esm/mcp/elicitation.test.js.map +1 -1
  250. package/esm/mcp/mcp-client.d.ts +6 -10
  251. package/esm/mcp/mcp-client.d.ts.map +1 -1
  252. package/esm/mcp/mcp-client.js.map +1 -1
  253. package/esm/mcp/mcp-constants.d.ts +19 -0
  254. package/esm/mcp/mcp-constants.d.ts.map +1 -0
  255. package/esm/mcp/mcp-constants.js +18 -0
  256. package/esm/mcp/mcp-constants.js.map +1 -0
  257. package/esm/mcp/mcp-hooks.d.ts +21 -40
  258. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  259. package/esm/mcp/mcp-hooks.js +97 -40
  260. package/esm/mcp/mcp-hooks.js.map +1 -1
  261. package/esm/mcp/mcp-hooks.test.js +431 -5
  262. package/esm/mcp/mcp-hooks.test.js.map +1 -1
  263. package/esm/mcp/tambo-mcp-provider.d.ts +7 -0
  264. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  265. package/esm/mcp/tambo-mcp-provider.js +204 -154
  266. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  267. package/esm/mcp/tambo-mcp-provider.test.js +37 -0
  268. package/esm/mcp/tambo-mcp-provider.test.js.map +1 -1
  269. package/esm/model/component-metadata.d.ts +54 -21
  270. package/esm/model/component-metadata.d.ts.map +1 -1
  271. package/esm/model/component-metadata.js.map +1 -1
  272. package/esm/model/tambo-interactable.d.ts +13 -5
  273. package/esm/model/tambo-interactable.d.ts.map +1 -1
  274. package/esm/model/tambo-interactable.js.map +1 -1
  275. package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts +2 -0
  276. package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +1 -0
  277. package/esm/providers/__tests__/thread-input-resource-resolution.test.js +587 -0
  278. package/esm/providers/__tests__/thread-input-resource-resolution.test.js.map +1 -0
  279. package/esm/providers/index.d.ts +1 -1
  280. package/esm/providers/index.d.ts.map +1 -1
  281. package/esm/providers/index.js.map +1 -1
  282. package/esm/providers/tambo-client-provider.d.ts +8 -0
  283. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  284. package/esm/providers/tambo-client-provider.js +11 -12
  285. package/esm/providers/tambo-client-provider.js.map +1 -1
  286. package/esm/providers/tambo-client-provider.test.d.ts +2 -0
  287. package/esm/providers/tambo-client-provider.test.d.ts.map +1 -0
  288. package/esm/providers/tambo-client-provider.test.js +203 -0
  289. package/esm/providers/tambo-client-provider.test.js.map +1 -0
  290. package/esm/providers/tambo-context-attachment-provider.d.ts +34 -92
  291. package/esm/providers/tambo-context-attachment-provider.d.ts.map +1 -1
  292. package/esm/providers/tambo-context-attachment-provider.js +63 -106
  293. package/esm/providers/tambo-context-attachment-provider.js.map +1 -1
  294. package/esm/providers/tambo-context-attachment-provider.test.js +230 -464
  295. package/esm/providers/tambo-context-attachment-provider.test.js.map +1 -1
  296. package/esm/providers/tambo-interactable-provider-partial-updates.test.js +22 -21
  297. package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  298. package/esm/providers/tambo-interactable-provider.d.ts +5 -2
  299. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  300. package/esm/providers/tambo-interactable-provider.js +126 -17
  301. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  302. package/esm/providers/tambo-interactable-provider.test.js +242 -0
  303. package/esm/providers/tambo-interactable-provider.test.js.map +1 -1
  304. package/esm/providers/tambo-interactables-additional-context.test.js +2 -5
  305. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  306. package/esm/providers/tambo-provider.d.ts +2 -3
  307. package/esm/providers/tambo-provider.d.ts.map +1 -1
  308. package/esm/providers/tambo-provider.js +6 -5
  309. package/esm/providers/tambo-provider.js.map +1 -1
  310. package/esm/providers/tambo-registry-provider.test.js +16 -0
  311. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  312. package/esm/providers/tambo-registry-schema-compat.test.js +31 -0
  313. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  314. package/esm/providers/tambo-thread-input-provider.d.ts +1 -1
  315. package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
  316. package/esm/providers/tambo-thread-input-provider.js +26 -4
  317. package/esm/providers/tambo-thread-input-provider.js.map +1 -1
  318. package/esm/providers/tambo-thread-provider-initial-messages.test.js +84 -2
  319. package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  320. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  321. package/esm/providers/tambo-thread-provider.js +53 -42
  322. package/esm/providers/tambo-thread-provider.js.map +1 -1
  323. package/esm/providers/tambo-thread-provider.test.js +368 -262
  324. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  325. package/esm/schema/index.d.ts +1 -1
  326. package/esm/schema/index.d.ts.map +1 -1
  327. package/esm/schema/index.js +1 -1
  328. package/esm/schema/index.js.map +1 -1
  329. package/esm/schema/json-schema.d.ts +7 -0
  330. package/esm/schema/json-schema.d.ts.map +1 -1
  331. package/esm/schema/json-schema.js +11 -1
  332. package/esm/schema/json-schema.js.map +1 -1
  333. package/esm/schema/json-schema.test.d.ts +2 -0
  334. package/esm/schema/json-schema.test.d.ts.map +1 -0
  335. package/esm/schema/json-schema.test.js +202 -0
  336. package/esm/schema/json-schema.test.js.map +1 -0
  337. package/esm/schema/schema.test.js +238 -1
  338. package/esm/schema/schema.test.js.map +1 -1
  339. package/esm/schema/standard-schema.d.ts +1 -0
  340. package/esm/schema/standard-schema.d.ts.map +1 -1
  341. package/esm/schema/standard-schema.js +18 -13
  342. package/esm/schema/standard-schema.js.map +1 -1
  343. package/esm/schema/standard-schema.test.d.ts +2 -0
  344. package/esm/schema/standard-schema.test.d.ts.map +1 -0
  345. package/esm/schema/standard-schema.test.js +130 -0
  346. package/esm/schema/standard-schema.test.js.map +1 -0
  347. package/esm/schema/validate.test.js +149 -0
  348. package/esm/schema/validate.test.js.map +1 -1
  349. package/esm/schema/zod.d.ts +7 -4
  350. package/esm/schema/zod.d.ts.map +1 -1
  351. package/esm/schema/zod.js +65 -22
  352. package/esm/schema/zod.js.map +1 -1
  353. package/esm/schema/zod.test.js +113 -1
  354. package/esm/schema/zod.test.js.map +1 -1
  355. package/esm/setupTests.js +3 -0
  356. package/esm/setupTests.js.map +1 -1
  357. package/esm/testing/tools.d.ts +4 -1
  358. package/esm/testing/tools.d.ts.map +1 -1
  359. package/esm/testing/tools.js +6 -1
  360. package/esm/testing/tools.js.map +1 -1
  361. package/esm/util/generate-component.d.ts.map +1 -1
  362. package/esm/util/generate-component.js +18 -3
  363. package/esm/util/generate-component.js.map +1 -1
  364. package/esm/util/generate-component.test.d.ts +2 -0
  365. package/esm/util/generate-component.test.d.ts.map +1 -0
  366. package/esm/util/generate-component.test.js +302 -0
  367. package/esm/util/generate-component.test.js.map +1 -0
  368. package/esm/util/is-promise.d.ts +9 -0
  369. package/esm/util/is-promise.d.ts.map +1 -0
  370. package/esm/util/is-promise.js +17 -0
  371. package/esm/util/is-promise.js.map +1 -0
  372. package/esm/util/is-promise.test.d.ts +2 -0
  373. package/esm/util/is-promise.test.d.ts.map +1 -0
  374. package/esm/util/is-promise.test.js +46 -0
  375. package/esm/util/is-promise.test.js.map +1 -0
  376. package/esm/util/message-builder.d.ts +3 -1
  377. package/esm/util/message-builder.d.ts.map +1 -1
  378. package/esm/util/message-builder.js +20 -3
  379. package/esm/util/message-builder.js.map +1 -1
  380. package/esm/util/message-builder.test.js +269 -0
  381. package/esm/util/message-builder.test.js.map +1 -1
  382. package/esm/util/query-utils.test.d.ts +2 -0
  383. package/esm/util/query-utils.test.d.ts.map +1 -0
  384. package/esm/util/query-utils.test.js +380 -0
  385. package/esm/util/query-utils.test.js.map +1 -0
  386. package/esm/util/registry-validators.d.ts.map +1 -1
  387. package/esm/util/registry-validators.js +7 -0
  388. package/esm/util/registry-validators.js.map +1 -1
  389. package/esm/util/registry-validators.test.js +57 -0
  390. package/esm/util/registry-validators.test.js.map +1 -1
  391. package/esm/util/registry.d.ts.map +1 -1
  392. package/esm/util/registry.js +9 -0
  393. package/esm/util/registry.js.map +1 -1
  394. package/esm/util/registry.test.js +324 -2
  395. package/esm/util/registry.test.js.map +1 -1
  396. package/esm/util/resource-content-resolver.d.ts +20 -0
  397. package/esm/util/resource-content-resolver.d.ts.map +1 -0
  398. package/esm/util/resource-content-resolver.js +89 -0
  399. package/esm/util/resource-content-resolver.js.map +1 -0
  400. package/esm/util/resource-content-resolver.test.d.ts +2 -0
  401. package/esm/util/resource-content-resolver.test.d.ts.map +1 -0
  402. package/esm/util/resource-content-resolver.test.js +252 -0
  403. package/esm/util/resource-content-resolver.test.js.map +1 -0
  404. package/esm/util/resource-validators.test.d.ts +2 -0
  405. package/esm/util/resource-validators.test.d.ts.map +1 -0
  406. package/esm/util/resource-validators.test.js +88 -0
  407. package/esm/util/resource-validators.test.js.map +1 -0
  408. package/esm/util/tool-caller.d.ts +2 -2
  409. package/esm/util/tool-caller.d.ts.map +1 -1
  410. package/esm/util/tool-caller.js +8 -8
  411. package/esm/util/tool-caller.js.map +1 -1
  412. package/esm/util/validate-component-name.test.d.ts +2 -0
  413. package/esm/util/validate-component-name.test.d.ts.map +1 -0
  414. package/esm/util/validate-component-name.test.js +33 -0
  415. package/esm/util/validate-component-name.test.js.map +1 -0
  416. package/package.json +15 -23
  417. package/dist/schema/alias.d.ts +0 -3
  418. package/dist/schema/alias.d.ts.map +0 -1
  419. package/dist/schema/alias.js +0 -6
  420. package/dist/schema/alias.js.map +0 -1
  421. package/esm/schema/alias.d.ts +0 -3
  422. package/esm/schema/alias.d.ts.map +0 -1
  423. package/esm/schema/alias.js +0 -13
  424. package/esm/schema/alias.js.map +0 -1
@@ -1,117 +1,77 @@
1
1
  "use client";
2
- import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
2
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
3
3
  import { useTamboContextHelpers } from "./tambo-context-helpers-provider";
4
4
  const ContextAttachmentContext = createContext(null);
5
+ const CONTEXT_ATTACHMENTS_HELPER_KEY = "contextAttachments";
5
6
  /**
6
- * Provider that enables context attachment features and custom suggestions in MessageInput.
7
- * **When to use:**
7
+ * Provider that manages context attachments for the next user message.
8
8
  * - **Included by default** in TamboProvider - no need to wrap separately
9
9
  * - Use `useTamboContextAttachment()` hook to manage context attachments
10
10
  * **What it does:**
11
- * - Manages context items that appear as badges above MessageInput
12
- * - Syncs context data with Tambo's AI for better responses
13
- * - Manages custom suggestions that replace auto-generated suggestions
14
- * - Allows components to add/remove contexts via `useTamboContextAttachment()`
15
- * - Allows components to set custom suggestions via `setCustomSuggestions()`
11
+ * - Stores context attachments that will be sent with the next message
12
+ * - Automatically registers/deregisters context helpers for each attachment
13
+ * - Context helpers are automatically collected during message submission
14
+ * - Context attachments are cleared after message submission (one-time use)
15
+ *
16
+ * **Note:** Context attachments are automatically included in additionalContext when
17
+ * the next message is sent. They are cleared after submission.
16
18
  * @param props - The props for the TamboContextAttachmentProvider
17
19
  * @param props.children - The children to wrap
18
- * @param props.getContextHelperData - The function to get the context helper data
19
20
  * @returns The TamboContextAttachmentProvider component
20
- * @example
21
- * Basic usage - already included in TamboProvider
22
- * ```tsx
23
- * <TamboProvider apiKey="...">
24
- * <App />
25
- * </TamboProvider>
26
- * ```
27
- * @example
28
- * Using TamboProvider with custom context data
29
- * ```tsx
30
- * <TamboProvider
31
- * apiKey="..."
32
- * getContextHelperData={(context) => ({
33
- * selectedComponent: {
34
- * name: context.name,
35
- * filePath: context.metadata?.path,
36
- * instruction: "Edit this component"
37
- * }
38
- * })}
39
- * >
40
- * <App />
41
- * </TamboProvider>
42
- * ```
43
21
  */
44
- export function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
45
- const [attachments, setAttachments] = useState([]);
46
- const [customSuggestions, setCustomSuggestions] = useState(null);
22
+ export function TamboContextAttachmentProvider({ children, }) {
47
23
  const { addContextHelper, removeContextHelper } = useTamboContextHelpers();
48
- // Track which context helpers have been registered to avoid duplicates
49
- const registeredIdsRef = useRef(new Set());
50
- const prevGetContextHelperDataRef = useRef();
51
- // Sync context helpers with attachments using useEffect
24
+ const [attachments, setAttachments] = useState([]);
52
25
  useEffect(() => {
53
- const currentIds = attachments.map((a) => a.id);
54
- const registeredIds = registeredIdsRef.current;
55
- // Remove context helpers that are no longer in attachments
56
- registeredIds.forEach((id) => {
57
- if (!currentIds.includes(id)) {
58
- removeContextHelper(id);
59
- registeredIds.delete(id);
26
+ addContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY, () => {
27
+ if (attachments.length === 0) {
28
+ return null;
60
29
  }
30
+ return attachments.map((attachment) => ({
31
+ id: attachment.id,
32
+ displayName: attachment.displayName,
33
+ context: attachment.context,
34
+ type: attachment.type,
35
+ }));
61
36
  });
62
- const getDataChanged = prevGetContextHelperDataRef.current !== getContextHelperData;
63
- // Add or replace context helpers for attachments
64
- attachments.forEach((context) => {
65
- if (getDataChanged || !registeredIds.has(context.id)) {
66
- addContextHelper(context.id, async () => {
67
- if (getContextHelperData) {
68
- return await getContextHelperData(context);
69
- }
70
- return {
71
- selectedComponent: {
72
- name: context.name,
73
- instruction: "This is a Tambo interactable component that is currently selected and visible on the dashboard. You can read its current props and state, and update it by modifying its props. If multiple components are attached, you can interact with and modify any of them. Use the auto-registered interactable component tools (like get_interactable_component_by_id and update_interactable_component_<id>) to view and update the component's state.",
74
- ...(context.metadata ?? {}),
75
- },
76
- };
77
- });
78
- registeredIds.add(context.id);
79
- }
80
- });
81
- prevGetContextHelperDataRef.current = getContextHelperData;
82
- }, [
83
- attachments,
84
- addContextHelper,
85
- removeContextHelper,
86
- getContextHelperData,
87
- ]);
88
- // Cleanup: remove all context helpers on unmount
89
- useEffect(() => {
90
- const registeredIds = registeredIdsRef.current;
91
37
  return () => {
92
- registeredIds.forEach((id) => {
93
- removeContextHelper(id);
94
- });
95
- registeredIds.clear();
38
+ removeContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY);
96
39
  };
97
- }, [removeContextHelper]);
98
- const addContextAttachment = useCallback((context) => {
99
- setAttachments((prev) => {
100
- if (prev.some((c) => c.name === context.name))
101
- return prev;
102
- if (typeof crypto === "undefined" || !("randomUUID" in crypto)) {
103
- throw new Error("crypto.randomUUID() is not available. This usually happens when using an IP address instead of 'localhost' in development. Use 'localhost' or a secure context (HTTPS) to enable crypto APIs.");
104
- }
105
- const newId = crypto.randomUUID();
106
- const newContext = { ...context, id: newId };
107
- return [...prev, newContext];
108
- });
40
+ }, [attachments, addContextHelper, removeContextHelper]);
41
+ /**
42
+ * Adds a new context attachment that will be included with the next user message.
43
+ * The attachment is automatically registered as part of the merged context helper.
44
+ * @param contextAttachment - The context attachment input (context, optional displayName, optional type)
45
+ * @returns The created ContextAttachment object with a unique ID
46
+ * @example
47
+ * ```tsx
48
+ * const attachment = addContextAttachment({
49
+ * context: "The contents of File.txt",
50
+ * displayName: "File.txt",
51
+ * type: "file"
52
+ * });
53
+ * ```
54
+ */
55
+ const addContextAttachment = useCallback((contextAttachment) => {
56
+ const id = crypto.randomUUID();
57
+ const attachment = {
58
+ id,
59
+ displayName: contextAttachment.displayName,
60
+ context: contextAttachment.context,
61
+ type: contextAttachment.type,
62
+ };
63
+ setAttachments((prev) => [...prev, attachment]);
64
+ return attachment;
109
65
  }, []);
110
- // This is used to remove a context when the user clicks the remove button
66
+ /**
67
+ * Removes a context attachment by its ID.
68
+ */
111
69
  const removeContextAttachment = useCallback((id) => {
112
70
  setAttachments((prev) => prev.filter((c) => c.id !== id));
113
71
  }, []);
114
- // This is used to clear the context when the user submits a message
72
+ /**
73
+ * Removes all context attachments at once.
74
+ */
115
75
  const clearContextAttachments = useCallback(() => {
116
76
  setAttachments([]);
117
77
  }, []);
@@ -120,14 +80,11 @@ export function TamboContextAttachmentProvider({ children, getContextHelperData,
120
80
  addContextAttachment,
121
81
  removeContextAttachment,
122
82
  clearContextAttachments,
123
- customSuggestions,
124
- setCustomSuggestions,
125
83
  }), [
126
84
  attachments,
127
85
  addContextAttachment,
128
86
  removeContextAttachment,
129
87
  clearContextAttachments,
130
- customSuggestions,
131
88
  ]);
132
89
  return (React.createElement(ContextAttachmentContext.Provider, { value: value }, children));
133
90
  }
@@ -138,20 +95,20 @@ export function TamboContextAttachmentProvider({ children, getContextHelperData,
138
95
  * @returns The context attachment state and methods
139
96
  * @example
140
97
  * ```tsx
141
- * const contextAttachment = useTamboContextAttachment();
98
+ * const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();
142
99
  *
143
- * // Add a context
144
- * contextAttachment.addContextAttachment({
145
- * name: "Button.tsx",
146
- * icon: <FileIcon />,
147
- * metadata: { path: "/src/Button.tsx" }
100
+ * // Add a context attachment for the next message
101
+ * const attachment = addContextAttachment({
102
+ * context: "The contents of File.txt",
103
+ * displayName: "File.txt", // optional
104
+ * type: "file" // optional
148
105
  * });
149
106
  *
150
- * // Remove a context
151
- * contextAttachment.removeContextAttachment(contextId);
107
+ * // Remove a context attachment
108
+ * removeContextAttachment(attachment.id);
152
109
  *
153
- * // Set custom suggestions
154
- * contextAttachment.setCustomSuggestions([{ id: "1", title: "Add Feature" }]);
110
+ * // Clear all context attachments
111
+ * clearContextAttachments();
155
112
  * ```
156
113
  */
157
114
  export function useTamboContextAttachment() {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-attachment-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAgD1E,MAAM,wBAAwB,GAAG,aAAa,CAC5C,IAAI,CACL,CAAC;AA2BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,8BAA8B,CAAC,EAC7C,QAAQ,EACR,oBAAoB,GACgB;IACpC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAsB,EAAE,CAAC,CAAC;IACxE,MA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AAG,IAAI,EAAE,UAAU,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC,EACD,EAAE,CACH,CAAC;IAEF,0EAA0E;IAC1E,MAAM,uBAAuB,GAAG,WAAW,CAAC,CAAC,EAAU,EAAE,EAAE;QACzD,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,oEAAoE;IACpE,MAAM,uBAAuB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/C,cAAc,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;QACvB,iBAAiB;QACjB,oBAAoB;KACrB,CAAC,EACF;QACE,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;QACvB,iBAAiB;KAClB,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,OAAO,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["\"use client\";\n\nimport type { Suggestion } from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\n/**\n * Represents a context attachment that can be displayed in MessageInputContexts.\n * Context attachments appear as badges above the message input and provide additional\n * information to the AI about what to focus on.\n * @property {string} name - Display name shown in the badge\n * @property {React.ReactNode} [icon] - Optional icon to display in the badge\n * @property {Record<string, unknown>} [metadata] - Additional data passed to the AI\n * @example\n * ```tsx\n * const context: ContextAttachment = {\n * name: \"Button.tsx\",\n * icon: <FileIcon />,\n * metadata: { filePath: \"/src/components/Button.tsx\" }\n * };\n * ```\n */\nexport interface ContextAttachment {\n id: string;\n name: string;\n icon?: React.ReactNode;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Represents the data structure returned by a context helper\n */\nexport type ContextHelperData = Record<string, unknown>;\n\n/**\n * Context state interface for managing context attachments and custom suggestions.\n * @property {ContextAttachment[]} attachments - Array of active context attachments (badges above message input)\n * @property {(context: Omit<ContextAttachment, \"id\">) => void} addContextAttachment - Add a new context attachment\n * @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID\n * @property {() => void} clearContextAttachments - Remove all context attachments - This is used to clear the context when the user submits a message\n * @property {Suggestion[] | null} customSuggestions - Custom suggestions to display instead of auto-generated ones\n * @property {(suggestions: Suggestion[] | null) => void} setCustomSuggestions - Set or clear custom suggestions\n */\nexport interface ContextAttachmentState {\n attachments: ContextAttachment[];\n addContextAttachment: (context: Omit<ContextAttachment, \"id\">) => void;\n removeContextAttachment: (id: string) => void;\n clearContextAttachments: () => void;\n customSuggestions: Suggestion[] | null;\n setCustomSuggestions: (suggestions: Suggestion[] | null) => void;\n}\n\nconst ContextAttachmentContext = createContext<ContextAttachmentState | null>(\n null,\n);\n\n/**\n * Props for the TamboContextAttachmentProvider.\n * @property {(context: ContextAttachment) => Promise<ContextHelperData> | ContextHelperData} [getContextHelperData] - Optional function to customize the data sent to the AI for each context. If not provided, uses a default structure with the context name and instruction.\n * @example\n * ```tsx\n * <TamboContextAttachmentProvider\n * getContextHelperData={(context) => ({\n * selectedFile: {\n * name: context.name,\n * path: context.metadata?.filePath,\n * instruction: \"Focus on this file\"\n * }\n * })}\n * >\n * {children}\n * </TamboContextAttachmentProvider>\n * ```\n */\nexport interface TamboContextAttachmentProviderProps {\n children?: React.ReactNode;\n getContextHelperData?: (\n context: ContextAttachment,\n ) => Promise<ContextHelperData> | ContextHelperData;\n}\n\n/**\n * Provider that enables context attachment features and custom suggestions in MessageInput.\n * **When to use:**\n * - **Included by default** in TamboProvider - no need to wrap separately\n * - Use `useTamboContextAttachment()` hook to manage context attachments\n * **What it does:**\n * - Manages context items that appear as badges above MessageInput\n * - Syncs context data with Tambo's AI for better responses\n * - Manages custom suggestions that replace auto-generated suggestions\n * - Allows components to add/remove contexts via `useTamboContextAttachment()`\n * - Allows components to set custom suggestions via `setCustomSuggestions()`\n * @param props - The props for the TamboContextAttachmentProvider\n * @param props.children - The children to wrap\n * @param props.getContextHelperData - The function to get the context helper data\n * @returns The TamboContextAttachmentProvider component\n * @example\n * Basic usage - already included in TamboProvider\n * ```tsx\n * <TamboProvider apiKey=\"...\">\n * <App />\n * </TamboProvider>\n * ```\n * @example\n * Using TamboProvider with custom context data\n * ```tsx\n * <TamboProvider\n * apiKey=\"...\"\n * getContextHelperData={(context) => ({\n * selectedComponent: {\n * name: context.name,\n * filePath: context.metadata?.path,\n * instruction: \"Edit this component\"\n * }\n * })}\n * >\n * <App />\n * </TamboProvider>\n * ```\n */\nexport function TamboContextAttachmentProvider({\n children,\n getContextHelperData,\n}: TamboContextAttachmentProviderProps) {\n const [attachments, setAttachments] = useState<ContextAttachment[]>([]);\n const [customSuggestions, setCustomSuggestions] = useState<\n Suggestion[] | null\n >(null);\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Track which context helpers have been registered to avoid duplicates\n const registeredIdsRef = useRef<Set<string>>(new Set());\n const prevGetContextHelperDataRef = useRef<typeof getContextHelperData>();\n\n // Sync context helpers with attachments using useEffect\n useEffect(() => {\n const currentIds = attachments.map((a) => a.id);\n const registeredIds = registeredIdsRef.current;\n\n // Remove context helpers that are no longer in attachments\n registeredIds.forEach((id) => {\n if (!currentIds.includes(id)) {\n removeContextHelper(id);\n registeredIds.delete(id);\n }\n });\n\n const getDataChanged =\n prevGetContextHelperDataRef.current !== getContextHelperData;\n\n // Add or replace context helpers for attachments\n attachments.forEach((context) => {\n if (getDataChanged || !registeredIds.has(context.id)) {\n addContextHelper(context.id, async (): Promise<ContextHelperData> => {\n if (getContextHelperData) {\n return await getContextHelperData(context);\n }\n return {\n selectedComponent: {\n name: context.name,\n instruction:\n \"This is a Tambo interactable component that is currently selected and visible on the dashboard. You can read its current props and state, and update it by modifying its props. If multiple components are attached, you can interact with and modify any of them. Use the auto-registered interactable component tools (like get_interactable_component_by_id and update_interactable_component_<id>) to view and update the component's state.\",\n ...(context.metadata ?? {}),\n },\n };\n });\n registeredIds.add(context.id);\n }\n });\n\n prevGetContextHelperDataRef.current = getContextHelperData;\n }, [\n attachments,\n addContextHelper,\n removeContextHelper,\n getContextHelperData,\n ]);\n\n // Cleanup: remove all context helpers on unmount\n useEffect(() => {\n const registeredIds = registeredIdsRef.current;\n return () => {\n registeredIds.forEach((id) => {\n removeContextHelper(id);\n });\n registeredIds.clear();\n };\n }, [removeContextHelper]);\n\n const addContextAttachment = useCallback(\n (context: Omit<ContextAttachment, \"id\">) => {\n setAttachments((prev) => {\n if (prev.some((c) => c.name === context.name)) return prev;\n\n if (typeof crypto === \"undefined\" || !(\"randomUUID\" in crypto)) {\n throw new Error(\n \"crypto.randomUUID() is not available. This usually happens when using an IP address instead of 'localhost' in development. Use 'localhost' or a secure context (HTTPS) to enable crypto APIs.\",\n );\n }\n\n const newId = crypto.randomUUID();\n const newContext = { ...context, id: newId };\n return [...prev, newContext];\n });\n },\n [],\n );\n\n // This is used to remove a context when the user clicks the remove button\n const removeContextAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n // This is used to clear the context when the user submits a message\n const clearContextAttachments = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const value = useMemo(\n () => ({\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n customSuggestions,\n setCustomSuggestions,\n }),\n [\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n customSuggestions,\n ],\n );\n\n return (\n <ContextAttachmentContext.Provider value={value}>\n {children}\n </ContextAttachmentContext.Provider>\n );\n}\n\n/**\n * Hook to access context attachment state and methods.\n * **Must be used within a `TamboProvider`** - throws an error otherwise.\n * @throws {Error} If used outside of TamboProvider\n * @returns The context attachment state and methods\n * @example\n * ```tsx\n * const contextAttachment = useTamboContextAttachment();\n *\n * // Add a context\n * contextAttachment.addContextAttachment({\n * name: \"Button.tsx\",\n * icon: <FileIcon />,\n * metadata: { path: \"/src/Button.tsx\" }\n * });\n *\n * // Remove a context\n * contextAttachment.removeContextAttachment(contextId);\n *\n * // Set custom suggestions\n * contextAttachment.setCustomSuggestions([{ id: \"1\", title: \"Add Feature\" }]);\n * ```\n */\nexport function useTamboContextAttachment() {\n const context = useContext(ContextAttachmentContext);\n if (!context) {\n throw new Error(\n \"useTamboContextAttachment must be used within a TamboContextAttachmentProvider\",\n );\n }\n return context;\n}\n"]}
1
+ {"version":3,"file":"tambo-context-attachment-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAkC1E,MAAM,wBAAwB,GAAG,aAAa,CAC5C,IAAI,CACL,CAAC;AAMF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,8BAA8B,CAAC,E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CAAC;IAEF;;OAEG;IACH,MAAM,uBAAuB,GAAG,WAAW,CAAC,CAAC,EAAU,EAAE,EAAE;QACzD,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP;;OAEG;IACH,MAAM,uBAAuB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/C,cAAc,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;KACxB,CAAC,EACF;QACE,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;KACxB,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,OAAO,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["\"use client\";\n\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\n/**\n * Represents a context attachment that will be sent with the next user message.\n * These are automatically registered as context helpers and will be included in\n * the additionalContext when the next message is sent.\n * @property {string} id - Unique identifier for this context attachment\n * @property {string} [displayName] - Optional display name for UI rendering\n * @property {string} context - The context value that will be used in additionalContext\n * @property {string} [type] - Optional type identifier for grouping/rendering multiple contexts of the same type\n */\nexport interface ContextAttachment {\n id: string;\n displayName?: string;\n context: string;\n type?: string;\n}\n\n/**\n * Context state interface for managing context attachments.\n * @property {ContextAttachment[]} attachments - Array of active context attachments\n * @property {(contextAttachment: Omit<ContextAttachment, \"id\">) => ContextAttachment} addContextAttachment - Add a new context attachment, returns the attachment\n * @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID\n * @property {() => void} clearContextAttachments - Remove all context attachments\n */\nexport interface ContextAttachmentState {\n attachments: ContextAttachment[];\n addContextAttachment: (\n contextAttachment: Omit<ContextAttachment, \"id\">,\n ) => ContextAttachment;\n removeContextAttachment: (id: string) => void;\n clearContextAttachments: () => void;\n}\n\nconst ContextAttachmentContext = createContext<ContextAttachmentState | null>(\n null,\n);\n\nexport interface TamboContextAttachmentProviderProps {\n children?: React.ReactNode;\n}\n\nconst CONTEXT_ATTACHMENTS_HELPER_KEY = \"contextAttachments\";\n\n/**\n * Provider that manages context attachments for the next user message.\n * - **Included by default** in TamboProvider - no need to wrap separately\n * - Use `useTamboContextAttachment()` hook to manage context attachments\n * **What it does:**\n * - Stores context attachments that will be sent with the next message\n * - Automatically registers/deregisters context helpers for each attachment\n * - Context helpers are automatically collected during message submission\n * - Context attachments are cleared after message submission (one-time use)\n *\n * **Note:** Context attachments are automatically included in additionalContext when\n * the next message is sent. They are cleared after submission.\n * @param props - The props for the TamboContextAttachmentProvider\n * @param props.children - The children to wrap\n * @returns The TamboContextAttachmentProvider component\n */\nexport function TamboContextAttachmentProvider({\n children,\n}: TamboContextAttachmentProviderProps) {\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n const [attachments, setAttachments] = useState<ContextAttachment[]>([]);\n\n useEffect(() => {\n addContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY, () => {\n if (attachments.length === 0) {\n return null;\n }\n\n return attachments.map((attachment) => ({\n id: attachment.id,\n displayName: attachment.displayName,\n context: attachment.context,\n type: attachment.type,\n }));\n });\n\n return () => {\n removeContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY);\n };\n }, [attachments, addContextHelper, removeContextHelper]);\n\n /**\n * Adds a new context attachment that will be included with the next user message.\n * The attachment is automatically registered as part of the merged context helper.\n * @param contextAttachment - The context attachment input (context, optional displayName, optional type)\n * @returns The created ContextAttachment object with a unique ID\n * @example\n * ```tsx\n * const attachment = addContextAttachment({\n * context: \"The contents of File.txt\",\n * displayName: \"File.txt\",\n * type: \"file\"\n * });\n * ```\n */\n const addContextAttachment = useCallback(\n (contextAttachment: Omit<ContextAttachment, \"id\">): ContextAttachment => {\n const id = crypto.randomUUID();\n const attachment: ContextAttachment = {\n id,\n displayName: contextAttachment.displayName,\n context: contextAttachment.context,\n type: contextAttachment.type,\n };\n setAttachments((prev) => [...prev, attachment]);\n\n return attachment;\n },\n [],\n );\n\n /**\n * Removes a context attachment by its ID.\n */\n const removeContextAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n /**\n * Removes all context attachments at once.\n */\n const clearContextAttachments = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const value = useMemo(\n () => ({\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n }),\n [\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n ],\n );\n\n return (\n <ContextAttachmentContext.Provider value={value}>\n {children}\n </ContextAttachmentContext.Provider>\n );\n}\n\n/**\n * Hook to access context attachment state and methods.\n * **Must be used within a `TamboProvider`** - throws an error otherwise.\n * @throws {Error} If used outside of TamboProvider\n * @returns The context attachment state and methods\n * @example\n * ```tsx\n * const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();\n *\n * // Add a context attachment for the next message\n * const attachment = addContextAttachment({\n * context: \"The contents of File.txt\",\n * displayName: \"File.txt\", // optional\n * type: \"file\" // optional\n * });\n *\n * // Remove a context attachment\n * removeContextAttachment(attachment.id);\n *\n * // Clear all context attachments\n * clearContextAttachments();\n * ```\n */\nexport function useTamboContextAttachment() {\n const context = useContext(ContextAttachmentContext);\n if (!context) {\n throw new Error(\n \"useTamboContextAttachment must be used within a TamboContextAttachmentProvider\",\n );\n }\n return context;\n}\n"]}