@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,110 +1,52 @@
1
- import type { Suggestion } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
2
1
  import React from "react";
3
2
  /**
4
- * Represents a context attachment that can be displayed in MessageInputContexts.
5
- * Context attachments appear as badges above the message input and provide additional
6
- * information to the AI about what to focus on.
7
- * @property {string} name - Display name shown in the badge
8
- * @property {React.ReactNode} [icon] - Optional icon to display in the badge
9
- * @property {Record<string, unknown>} [metadata] - Additional data passed to the AI
10
- * @example
11
- * ```tsx
12
- * const context: ContextAttachment = {
13
- * name: "Button.tsx",
14
- * icon: <FileIcon />,
15
- * metadata: { filePath: "/src/components/Button.tsx" }
16
- * };
17
- * ```
3
+ * Represents a context attachment that will be sent with the next user message.
4
+ * These are automatically registered as context helpers and will be included in
5
+ * the additionalContext when the next message is sent.
6
+ * @property {string} id - Unique identifier for this context attachment
7
+ * @property {string} [displayName] - Optional display name for UI rendering
8
+ * @property {string} context - The context value that will be used in additionalContext
9
+ * @property {string} [type] - Optional type identifier for grouping/rendering multiple contexts of the same type
18
10
  */
19
11
  export interface ContextAttachment {
20
12
  id: string;
21
- name: string;
22
- icon?: React.ReactNode;
23
- metadata?: Record<string, unknown>;
13
+ displayName?: string;
14
+ context: string;
15
+ type?: string;
24
16
  }
25
17
  /**
26
- * Represents the data structure returned by a context helper
27
- */
28
- export type ContextHelperData = Record<string, unknown>;
29
- /**
30
- * Context state interface for managing context attachments and custom suggestions.
31
- * @property {ContextAttachment[]} attachments - Array of active context attachments (badges above message input)
32
- * @property {(context: Omit<ContextAttachment, "id">) => void} addContextAttachment - Add a new context attachment
18
+ * Context state interface for managing context attachments.
19
+ * @property {ContextAttachment[]} attachments - Array of active context attachments
20
+ * @property {(contextAttachment: Omit<ContextAttachment, "id">) => ContextAttachment} addContextAttachment - Add a new context attachment, returns the attachment
33
21
  * @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID
34
- * @property {() => void} clearContextAttachments - Remove all context attachments - This is used to clear the context when the user submits a message
35
- * @property {Suggestion[] | null} customSuggestions - Custom suggestions to display instead of auto-generated ones
36
- * @property {(suggestions: Suggestion[] | null) => void} setCustomSuggestions - Set or clear custom suggestions
22
+ * @property {() => void} clearContextAttachments - Remove all context attachments
37
23
  */
38
24
  export interface ContextAttachmentState {
39
25
  attachments: ContextAttachment[];
40
- addContextAttachment: (context: Omit<ContextAttachment, "id">) => void;
26
+ addContextAttachment: (contextAttachment: Omit<ContextAttachment, "id">) => ContextAttachment;
41
27
  removeContextAttachment: (id: string) => void;
42
28
  clearContextAttachments: () => void;
43
- customSuggestions: Suggestion[] | null;
44
- setCustomSuggestions: (suggestions: Suggestion[] | null) => void;
45
29
  }
46
- /**
47
- * Props for the TamboContextAttachmentProvider.
48
- * @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.
49
- * @example
50
- * ```tsx
51
- * <TamboContextAttachmentProvider
52
- * getContextHelperData={(context) => ({
53
- * selectedFile: {
54
- * name: context.name,
55
- * path: context.metadata?.filePath,
56
- * instruction: "Focus on this file"
57
- * }
58
- * })}
59
- * >
60
- * {children}
61
- * </TamboContextAttachmentProvider>
62
- * ```
63
- */
64
30
  export interface TamboContextAttachmentProviderProps {
65
31
  children?: React.ReactNode;
66
- getContextHelperData?: (context: ContextAttachment) => Promise<ContextHelperData> | ContextHelperData;
67
32
  }
68
33
  /**
69
- * Provider that enables context attachment features and custom suggestions in MessageInput.
70
- * **When to use:**
34
+ * Provider that manages context attachments for the next user message.
71
35
  * - **Included by default** in TamboProvider - no need to wrap separately
72
36
  * - Use `useTamboContextAttachment()` hook to manage context attachments
73
37
  * **What it does:**
74
- * - Manages context items that appear as badges above MessageInput
75
- * - Syncs context data with Tambo's AI for better responses
76
- * - Manages custom suggestions that replace auto-generated suggestions
77
- * - Allows components to add/remove contexts via `useTamboContextAttachment()`
78
- * - Allows components to set custom suggestions via `setCustomSuggestions()`
38
+ * - Stores context attachments that will be sent with the next message
39
+ * - Automatically registers/deregisters context helpers for each attachment
40
+ * - Context helpers are automatically collected during message submission
41
+ * - Context attachments are cleared after message submission (one-time use)
42
+ *
43
+ * **Note:** Context attachments are automatically included in additionalContext when
44
+ * the next message is sent. They are cleared after submission.
79
45
  * @param props - The props for the TamboContextAttachmentProvider
80
46
  * @param props.children - The children to wrap
81
- * @param props.getContextHelperData - The function to get the context helper data
82
47
  * @returns The TamboContextAttachmentProvider component
83
- * @example
84
- * Basic usage - already included in TamboProvider
85
- * ```tsx
86
- * <TamboProvider apiKey="...">
87
- * <App />
88
- * </TamboProvider>
89
- * ```
90
- * @example
91
- * Using TamboProvider with custom context data
92
- * ```tsx
93
- * <TamboProvider
94
- * apiKey="..."
95
- * getContextHelperData={(context) => ({
96
- * selectedComponent: {
97
- * name: context.name,
98
- * filePath: context.metadata?.path,
99
- * instruction: "Edit this component"
100
- * }
101
- * })}
102
- * >
103
- * <App />
104
- * </TamboProvider>
105
- * ```
106
48
  */
107
- export declare function TamboContextAttachmentProvider({ children, getContextHelperData, }: TamboContextAttachmentProviderProps): React.JSX.Element;
49
+ export declare function TamboContextAttachmentProvider({ children, }: TamboContextAttachmentProviderProps): React.JSX.Element;
108
50
  /**
109
51
  * Hook to access context attachment state and methods.
110
52
  * **Must be used within a `TamboProvider`** - throws an error otherwise.
@@ -112,20 +54,20 @@ export declare function TamboContextAttachmentProvider({ children, getContextHel
112
54
  * @returns The context attachment state and methods
113
55
  * @example
114
56
  * ```tsx
115
- * const contextAttachment = useTamboContextAttachment();
57
+ * const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();
116
58
  *
117
- * // Add a context
118
- * contextAttachment.addContextAttachment({
119
- * name: "Button.tsx",
120
- * icon: <FileIcon />,
121
- * metadata: { path: "/src/Button.tsx" }
59
+ * // Add a context attachment for the next message
60
+ * const attachment = addContextAttachment({
61
+ * context: "The contents of File.txt",
62
+ * displayName: "File.txt", // optional
63
+ * type: "file" // optional
122
64
  * });
123
65
  *
124
- * // Remove a context
125
- * contextAttachment.removeContextAttachment(contextId);
66
+ * // Remove a context attachment
67
+ * removeContextAttachment(attachment.id);
126
68
  *
127
- * // Set custom suggestions
128
- * contextAttachment.setCustomSuggestions([{ id: "1", title: "Add Feature" }]);
69
+ * // Clear all context attachments
70
+ * clearContextAttachments();
129
71
  * ```
130
72
  */
131
73
  export declare function useTamboContextAttachment(): ContextAttachmentState;
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-attachment-provider.d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,EAAE,mCAAmC,qBAsHrC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,2BAQxC"}
1
+ {"version":3,"file":"tambo-context-attachment-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,MAAM,OAAO,CAAC;AAGf;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,oBAAoB,EAAE,CACpB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAC7C,iBAAiB,CAAC;IACvB,uBAAuB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,uBAAuB,EAAE,MAAM,IAAI,CAAC;CACrC;AAMD,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,QAAQ,GACT,EAAE,mCAAmC,qBAuFrC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,2BAQxC"}
@@ -39,116 +39,76 @@ exports.useTamboContextAttachment = useTamboContextAttachment;
39
39
  const react_1 = __importStar(require("react"));
40
40
  const tambo_context_helpers_provider_1 = require("./tambo-context-helpers-provider");
41
41
  const ContextAttachmentContext = (0, react_1.createContext)(null);
42
+ const CONTEXT_ATTACHMENTS_HELPER_KEY = "contextAttachments";
42
43
  /**
43
- * Provider that enables context attachment features and custom suggestions in MessageInput.
44
- * **When to use:**
44
+ * Provider that manages context attachments for the next user message.
45
45
  * - **Included by default** in TamboProvider - no need to wrap separately
46
46
  * - Use `useTamboContextAttachment()` hook to manage context attachments
47
47
  * **What it does:**
48
- * - Manages context items that appear as badges above MessageInput
49
- * - Syncs context data with Tambo's AI for better responses
50
- * - Manages custom suggestions that replace auto-generated suggestions
51
- * - Allows components to add/remove contexts via `useTamboContextAttachment()`
52
- * - Allows components to set custom suggestions via `setCustomSuggestions()`
48
+ * - Stores context attachments that will be sent with the next message
49
+ * - Automatically registers/deregisters context helpers for each attachment
50
+ * - Context helpers are automatically collected during message submission
51
+ * - Context attachments are cleared after message submission (one-time use)
52
+ *
53
+ * **Note:** Context attachments are automatically included in additionalContext when
54
+ * the next message is sent. They are cleared after submission.
53
55
  * @param props - The props for the TamboContextAttachmentProvider
54
56
  * @param props.children - The children to wrap
55
- * @param props.getContextHelperData - The function to get the context helper data
56
57
  * @returns The TamboContextAttachmentProvider component
57
- * @example
58
- * Basic usage - already included in TamboProvider
59
- * ```tsx
60
- * <TamboProvider apiKey="...">
61
- * <App />
62
- * </TamboProvider>
63
- * ```
64
- * @example
65
- * Using TamboProvider with custom context data
66
- * ```tsx
67
- * <TamboProvider
68
- * apiKey="..."
69
- * getContextHelperData={(context) => ({
70
- * selectedComponent: {
71
- * name: context.name,
72
- * filePath: context.metadata?.path,
73
- * instruction: "Edit this component"
74
- * }
75
- * })}
76
- * >
77
- * <App />
78
- * </TamboProvider>
79
- * ```
80
58
  */
81
- function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
82
- const [attachments, setAttachments] = (0, react_1.useState)([]);
83
- const [customSuggestions, setCustomSuggestions] = (0, react_1.useState)(null);
59
+ function TamboContextAttachmentProvider({ children, }) {
84
60
  const { addContextHelper, removeContextHelper } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
85
- // Track which context helpers have been registered to avoid duplicates
86
- const registeredIdsRef = (0, react_1.useRef)(new Set());
87
- const prevGetContextHelperDataRef = (0, react_1.useRef)();
88
- // Sync context helpers with attachments using useEffect
61
+ const [attachments, setAttachments] = (0, react_1.useState)([]);
89
62
  (0, react_1.useEffect)(() => {
90
- const currentIds = attachments.map((a) => a.id);
91
- const registeredIds = registeredIdsRef.current;
92
- // Remove context helpers that are no longer in attachments
93
- registeredIds.forEach((id) => {
94
- if (!currentIds.includes(id)) {
95
- removeContextHelper(id);
96
- registeredIds.delete(id);
63
+ addContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY, () => {
64
+ if (attachments.length === 0) {
65
+ return null;
97
66
  }
67
+ return attachments.map((attachment) => ({
68
+ id: attachment.id,
69
+ displayName: attachment.displayName,
70
+ context: attachment.context,
71
+ type: attachment.type,
72
+ }));
98
73
  });
99
- const getDataChanged = prevGetContextHelperDataRef.current !== getContextHelperData;
100
- // Add or replace context helpers for attachments
101
- attachments.forEach((context) => {
102
- if (getDataChanged || !registeredIds.has(context.id)) {
103
- addContextHelper(context.id, async () => {
104
- if (getContextHelperData) {
105
- return await getContextHelperData(context);
106
- }
107
- return {
108
- selectedComponent: {
109
- name: context.name,
110
- 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.",
111
- ...(context.metadata ?? {}),
112
- },
113
- };
114
- });
115
- registeredIds.add(context.id);
116
- }
117
- });
118
- prevGetContextHelperDataRef.current = getContextHelperData;
119
- }, [
120
- attachments,
121
- addContextHelper,
122
- removeContextHelper,
123
- getContextHelperData,
124
- ]);
125
- // Cleanup: remove all context helpers on unmount
126
- (0, react_1.useEffect)(() => {
127
- const registeredIds = registeredIdsRef.current;
128
74
  return () => {
129
- registeredIds.forEach((id) => {
130
- removeContextHelper(id);
131
- });
132
- registeredIds.clear();
75
+ removeContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY);
133
76
  };
134
- }, [removeContextHelper]);
135
- const addContextAttachment = (0, react_1.useCallback)((context) => {
136
- setAttachments((prev) => {
137
- if (prev.some((c) => c.name === context.name))
138
- return prev;
139
- if (typeof crypto === "undefined" || !("randomUUID" in crypto)) {
140
- 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.");
141
- }
142
- const newId = crypto.randomUUID();
143
- const newContext = { ...context, id: newId };
144
- return [...prev, newContext];
145
- });
77
+ }, [attachments, addContextHelper, removeContextHelper]);
78
+ /**
79
+ * Adds a new context attachment that will be included with the next user message.
80
+ * The attachment is automatically registered as part of the merged context helper.
81
+ * @param contextAttachment - The context attachment input (context, optional displayName, optional type)
82
+ * @returns The created ContextAttachment object with a unique ID
83
+ * @example
84
+ * ```tsx
85
+ * const attachment = addContextAttachment({
86
+ * context: "The contents of File.txt",
87
+ * displayName: "File.txt",
88
+ * type: "file"
89
+ * });
90
+ * ```
91
+ */
92
+ const addContextAttachment = (0, react_1.useCallback)((contextAttachment) => {
93
+ const id = crypto.randomUUID();
94
+ const attachment = {
95
+ id,
96
+ displayName: contextAttachment.displayName,
97
+ context: contextAttachment.context,
98
+ type: contextAttachment.type,
99
+ };
100
+ setAttachments((prev) => [...prev, attachment]);
101
+ return attachment;
146
102
  }, []);
147
- // This is used to remove a context when the user clicks the remove button
103
+ /**
104
+ * Removes a context attachment by its ID.
105
+ */
148
106
  const removeContextAttachment = (0, react_1.useCallback)((id) => {
149
107
  setAttachments((prev) => prev.filter((c) => c.id !== id));
150
108
  }, []);
151
- // This is used to clear the context when the user submits a message
109
+ /**
110
+ * Removes all context attachments at once.
111
+ */
152
112
  const clearContextAttachments = (0, react_1.useCallback)(() => {
153
113
  setAttachments([]);
154
114
  }, []);
@@ -157,14 +117,11 @@ function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
157
117
  addContextAttachment,
158
118
  removeContextAttachment,
159
119
  clearContextAttachments,
160
- customSuggestions,
161
- setCustomSuggestions,
162
120
  }), [
163
121
  attachments,
164
122
  addContextAttachment,
165
123
  removeContextAttachment,
166
124
  clearContextAttachments,
167
- customSuggestions,
168
125
  ]);
169
126
  return (react_1.default.createElement(ContextAttachmentContext.Provider, { value: value }, children));
170
127
  }
@@ -175,20 +132,20 @@ function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
175
132
  * @returns The context attachment state and methods
176
133
  * @example
177
134
  * ```tsx
178
- * const contextAttachment = useTamboContextAttachment();
135
+ * const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();
179
136
  *
180
- * // Add a context
181
- * contextAttachment.addContextAttachment({
182
- * name: "Button.tsx",
183
- * icon: <FileIcon />,
184
- * metadata: { path: "/src/Button.tsx" }
137
+ * // Add a context attachment for the next message
138
+ * const attachment = addContextAttachment({
139
+ * context: "The contents of File.txt",
140
+ * displayName: "File.txt", // optional
141
+ * type: "file" // optional
185
142
  * });
186
143
  *
187
- * // Remove a context
188
- * contextAttachment.removeContextAttachment(contextId);
144
+ * // Remove a context attachment
145
+ * removeContextAttachment(attachment.id);
189
146
  *
190
- * // Set custom suggestions
191
- * contextAttachment.setCustomSuggestions([{ id: "1", title: "Add Feature" }]);
147
+ * // Clear all context attachments
148
+ * clearContextAttachments();
192
149
  * ```
193
150
  */
194
151
  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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIb,wEAyHC;AAyBD,8DAQC;AAvRD,+CAQe;AACf,qFAA0E;AAgD1E,MAAM,wBAAwB,GAAG,IAAA,qBAAa,EAC5C,IAAI,CACL,CAAC;AA2BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,8BAA8B,CAAC,EAC7C,QAAQ,EACR,oBAAoB,GACgB;IACpC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,G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Content":["\"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEb,wEAyFC;AAyBD,8DAQC;AA9LD,+CAOe;AACf,qFAA0E;AAkC1E,MAAM,wBAAwB,GAAG,IAAA,qBAAa,EAC5C,IAAI,CACL,CAAC;AAMF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;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I,EAAE,UAAU,CAAC,CAAC,CAAC;QAEhD,OAAO,UAAU,CAAC;IACpB,CAAC,EACD,EAAE,CACH,CAAC;IAEF;;OAEG;IACH,MAAM,uBAAuB,GAAG,IAAA,mBAAW,EAAC,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,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/C,cAAc,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,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,8BAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,yBAAyB;IACvC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,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"]}