@tambo-ai/react 0.65.3 → 0.66.1

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 (346) hide show
  1. package/README.md +120 -20
  2. package/dist/{providers/hoc → hoc}/with-tambo-interactable.d.ts +2 -2
  3. package/dist/hoc/with-tambo-interactable.d.ts.map +1 -0
  4. package/dist/{providers/hoc → hoc}/with-tambo-interactable.js +29 -2
  5. package/dist/hoc/with-tambo-interactable.js.map +1 -0
  6. package/dist/hoc/with-tambo-interactable.test.d.ts +2 -0
  7. package/dist/hoc/with-tambo-interactable.test.d.ts.map +1 -0
  8. package/dist/hoc/with-tambo-interactable.test.js +192 -0
  9. package/dist/hoc/with-tambo-interactable.test.js.map +1 -0
  10. package/dist/hooks/index.d.ts +1 -1
  11. package/dist/hooks/index.d.ts.map +1 -1
  12. package/dist/hooks/index.js +2 -1
  13. package/dist/hooks/index.js.map +1 -1
  14. package/dist/hooks/use-current-message.d.ts +51 -7
  15. package/dist/hooks/use-current-message.d.ts.map +1 -1
  16. package/dist/hooks/use-current-message.js +50 -6
  17. package/dist/hooks/use-current-message.js.map +1 -1
  18. package/dist/hooks/use-current-message.test.d.ts +2 -0
  19. package/dist/hooks/use-current-message.test.d.ts.map +1 -0
  20. package/dist/hooks/use-current-message.test.js +264 -0
  21. package/dist/hooks/use-current-message.test.js.map +1 -0
  22. package/dist/index.d.ts +10 -8
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +7 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/mcp/index.d.ts +1 -1
  27. package/dist/mcp/index.d.ts.map +1 -1
  28. package/dist/mcp/index.js +2 -1
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/mcp/mcp-hooks.d.ts +77 -6
  31. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  32. package/dist/mcp/mcp-hooks.js +104 -40
  33. package/dist/mcp/mcp-hooks.js.map +1 -1
  34. package/dist/mcp/mcp-hooks.test.js +83 -18
  35. package/dist/mcp/mcp-hooks.test.js.map +1 -1
  36. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  37. package/dist/mcp/tambo-mcp-provider.js +2 -1
  38. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  39. package/dist/model/component-metadata.d.ts +444 -14
  40. package/dist/model/component-metadata.d.ts.map +1 -1
  41. package/dist/model/component-metadata.js.map +1 -1
  42. package/dist/model/generate-component-response.d.ts +12 -1
  43. package/dist/model/generate-component-response.d.ts.map +1 -1
  44. package/dist/model/generate-component-response.js.map +1 -1
  45. package/dist/model/resource-info.d.ts +55 -0
  46. package/dist/model/resource-info.d.ts.map +1 -0
  47. package/dist/model/resource-info.js +3 -0
  48. package/dist/model/resource-info.js.map +1 -0
  49. package/dist/providers/index.d.ts +1 -1
  50. package/dist/providers/index.d.ts.map +1 -1
  51. package/dist/providers/index.js.map +1 -1
  52. package/dist/providers/tambo-component-provider.d.ts +4 -4
  53. package/dist/providers/tambo-component-provider.d.ts.map +1 -1
  54. package/dist/providers/tambo-component-provider.js.map +1 -1
  55. package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
  56. package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  57. package/dist/providers/tambo-interactable-provider.d.ts +2 -3
  58. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  59. package/dist/providers/tambo-interactable-provider.js +47 -41
  60. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  61. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +9 -9
  62. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  63. package/dist/providers/tambo-interactables-additional-context.test.js +11 -11
  64. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  65. package/dist/providers/tambo-registry-provider.d.ts +28 -7
  66. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  67. package/dist/providers/tambo-registry-provider.js +70 -181
  68. package/dist/providers/tambo-registry-provider.js.map +1 -1
  69. package/dist/providers/tambo-registry-provider.test.js +152 -30
  70. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  71. package/dist/providers/tambo-registry-schema-compat.test.d.ts +2 -0
  72. package/dist/providers/tambo-registry-schema-compat.test.d.ts.map +1 -0
  73. package/dist/providers/tambo-registry-schema-compat.test.js +616 -0
  74. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -0
  75. package/dist/providers/tambo-stubs.d.ts +2 -2
  76. package/dist/providers/tambo-stubs.d.ts.map +1 -1
  77. package/dist/providers/tambo-stubs.js +5 -0
  78. package/dist/providers/tambo-stubs.js.map +1 -1
  79. package/dist/providers/tambo-thread-input-provider.d.ts +1 -0
  80. package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
  81. package/dist/providers/tambo-thread-input-provider.js +3 -3
  82. package/dist/providers/tambo-thread-input-provider.js.map +1 -1
  83. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  84. package/dist/providers/tambo-thread-provider.js.map +1 -1
  85. package/dist/providers/tambo-thread-provider.test.js +32 -36
  86. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  87. package/dist/schema/index.d.ts +6 -0
  88. package/dist/schema/index.d.ts.map +1 -0
  89. package/dist/schema/index.js +18 -0
  90. package/dist/schema/index.js.map +1 -0
  91. package/dist/schema/json-schema.d.ts +35 -0
  92. package/dist/schema/json-schema.d.ts.map +1 -0
  93. package/dist/schema/json-schema.js +103 -0
  94. package/dist/schema/json-schema.js.map +1 -0
  95. package/dist/schema/schema.d.ts +66 -0
  96. package/dist/schema/schema.d.ts.map +1 -0
  97. package/dist/schema/schema.js +189 -0
  98. package/dist/schema/schema.js.map +1 -0
  99. package/dist/schema/schema.test.d.ts +2 -0
  100. package/dist/schema/schema.test.d.ts.map +1 -0
  101. package/dist/schema/schema.test.js +41 -0
  102. package/dist/schema/schema.test.js.map +1 -0
  103. package/dist/schema/standard-schema.d.ts +21 -0
  104. package/dist/schema/standard-schema.d.ts.map +1 -0
  105. package/dist/schema/standard-schema.js +37 -0
  106. package/dist/schema/standard-schema.js.map +1 -0
  107. package/dist/schema/validate.d.ts +14 -0
  108. package/dist/schema/validate.d.ts.map +1 -0
  109. package/dist/schema/validate.js +148 -0
  110. package/dist/schema/validate.js.map +1 -0
  111. package/dist/schema/validate.test.d.ts +2 -0
  112. package/dist/schema/validate.test.d.ts.map +1 -0
  113. package/dist/schema/validate.test.js +128 -0
  114. package/dist/schema/validate.test.js.map +1 -0
  115. package/dist/schema/zod.d.ts +54 -0
  116. package/dist/schema/zod.d.ts.map +1 -0
  117. package/dist/schema/zod.js +147 -0
  118. package/dist/schema/zod.js.map +1 -0
  119. package/dist/testing/tools.d.ts +29 -15
  120. package/dist/testing/tools.d.ts.map +1 -1
  121. package/dist/testing/tools.js +64 -19
  122. package/dist/testing/tools.js.map +1 -1
  123. package/dist/util/generate-component.d.ts.map +1 -1
  124. package/dist/util/generate-component.js +3 -3
  125. package/dist/util/generate-component.js.map +1 -1
  126. package/dist/util/mcp-server-utils.d.ts +23 -0
  127. package/dist/util/mcp-server-utils.d.ts.map +1 -0
  128. package/dist/util/mcp-server-utils.js +107 -0
  129. package/dist/util/mcp-server-utils.js.map +1 -0
  130. package/dist/util/mcp-server-utils.test.d.ts +2 -0
  131. package/dist/util/mcp-server-utils.test.d.ts.map +1 -0
  132. package/dist/util/mcp-server-utils.test.js +287 -0
  133. package/dist/util/mcp-server-utils.test.js.map +1 -0
  134. package/dist/util/message-builder.d.ts +2 -1
  135. package/dist/util/message-builder.d.ts.map +1 -1
  136. package/dist/util/message-builder.js +54 -36
  137. package/dist/util/message-builder.js.map +1 -1
  138. package/dist/util/message-builder.test.js +500 -13
  139. package/dist/util/message-builder.test.js.map +1 -1
  140. package/dist/util/registry-validators.d.ts +26 -0
  141. package/dist/util/registry-validators.d.ts.map +1 -0
  142. package/dist/util/registry-validators.js +105 -0
  143. package/dist/util/registry-validators.js.map +1 -0
  144. package/dist/util/registry-validators.test.d.ts +2 -0
  145. package/dist/util/registry-validators.test.d.ts.map +1 -0
  146. package/dist/util/registry-validators.test.js +235 -0
  147. package/dist/util/registry-validators.test.js.map +1 -0
  148. package/dist/util/registry.d.ts +35 -7
  149. package/dist/util/registry.d.ts.map +1 -1
  150. package/dist/util/registry.js +60 -77
  151. package/dist/util/registry.js.map +1 -1
  152. package/dist/util/registry.test.d.ts +2 -0
  153. package/dist/util/registry.test.d.ts.map +1 -0
  154. package/dist/util/registry.test.js +204 -0
  155. package/dist/util/registry.test.js.map +1 -0
  156. package/dist/util/resource-validators.d.ts +16 -0
  157. package/dist/util/resource-validators.d.ts.map +1 -0
  158. package/dist/util/resource-validators.js +34 -0
  159. package/dist/util/resource-validators.js.map +1 -0
  160. package/dist/util/tool-caller.d.ts +2 -2
  161. package/dist/util/tool-caller.d.ts.map +1 -1
  162. package/dist/util/tool-caller.js +12 -4
  163. package/dist/util/tool-caller.js.map +1 -1
  164. package/esm/{providers/hoc → hoc}/with-tambo-interactable.d.ts +2 -2
  165. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -0
  166. package/esm/{providers/hoc → hoc}/with-tambo-interactable.js +29 -2
  167. package/esm/hoc/with-tambo-interactable.js.map +1 -0
  168. package/esm/hoc/with-tambo-interactable.test.d.ts +2 -0
  169. package/esm/hoc/with-tambo-interactable.test.d.ts.map +1 -0
  170. package/esm/hoc/with-tambo-interactable.test.js +187 -0
  171. package/esm/hoc/with-tambo-interactable.test.js.map +1 -0
  172. package/esm/hooks/index.d.ts +1 -1
  173. package/esm/hooks/index.d.ts.map +1 -1
  174. package/esm/hooks/index.js +1 -1
  175. package/esm/hooks/index.js.map +1 -1
  176. package/esm/hooks/use-current-message.d.ts +51 -7
  177. package/esm/hooks/use-current-message.d.ts.map +1 -1
  178. package/esm/hooks/use-current-message.js +48 -5
  179. package/esm/hooks/use-current-message.js.map +1 -1
  180. package/esm/hooks/use-current-message.test.d.ts +2 -0
  181. package/esm/hooks/use-current-message.test.d.ts.map +1 -0
  182. package/esm/hooks/use-current-message.test.js +259 -0
  183. package/esm/hooks/use-current-message.test.js.map +1 -0
  184. package/esm/index.d.ts +10 -8
  185. package/esm/index.d.ts.map +1 -1
  186. package/esm/index.js +4 -2
  187. package/esm/index.js.map +1 -1
  188. package/esm/mcp/index.d.ts +1 -1
  189. package/esm/mcp/index.d.ts.map +1 -1
  190. package/esm/mcp/index.js +1 -1
  191. package/esm/mcp/index.js.map +1 -1
  192. package/esm/mcp/mcp-hooks.d.ts +77 -6
  193. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  194. package/esm/mcp/mcp-hooks.js +103 -40
  195. package/esm/mcp/mcp-hooks.js.map +1 -1
  196. package/esm/mcp/mcp-hooks.test.js +84 -19
  197. package/esm/mcp/mcp-hooks.test.js.map +1 -1
  198. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  199. package/esm/mcp/tambo-mcp-provider.js +2 -1
  200. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  201. package/esm/model/component-metadata.d.ts +444 -14
  202. package/esm/model/component-metadata.d.ts.map +1 -1
  203. package/esm/model/component-metadata.js.map +1 -1
  204. package/esm/model/generate-component-response.d.ts +12 -1
  205. package/esm/model/generate-component-response.d.ts.map +1 -1
  206. package/esm/model/generate-component-response.js.map +1 -1
  207. package/esm/model/resource-info.d.ts +55 -0
  208. package/esm/model/resource-info.d.ts.map +1 -0
  209. package/esm/model/resource-info.js +2 -0
  210. package/esm/model/resource-info.js.map +1 -0
  211. package/esm/providers/index.d.ts +1 -1
  212. package/esm/providers/index.d.ts.map +1 -1
  213. package/esm/providers/index.js.map +1 -1
  214. package/esm/providers/tambo-component-provider.d.ts +4 -4
  215. package/esm/providers/tambo-component-provider.d.ts.map +1 -1
  216. package/esm/providers/tambo-component-provider.js.map +1 -1
  217. package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
  218. package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  219. package/esm/providers/tambo-interactable-provider.d.ts +2 -3
  220. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  221. package/esm/providers/tambo-interactable-provider.js +44 -38
  222. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  223. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +3 -3
  224. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  225. package/esm/providers/tambo-interactables-additional-context.test.js +3 -3
  226. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  227. package/esm/providers/tambo-registry-provider.d.ts +28 -7
  228. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  229. package/esm/providers/tambo-registry-provider.js +67 -175
  230. package/esm/providers/tambo-registry-provider.js.map +1 -1
  231. package/esm/providers/tambo-registry-provider.test.js +148 -26
  232. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  233. package/esm/providers/tambo-registry-schema-compat.test.d.ts +2 -0
  234. package/esm/providers/tambo-registry-schema-compat.test.d.ts.map +1 -0
  235. package/esm/providers/tambo-registry-schema-compat.test.js +578 -0
  236. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -0
  237. package/esm/providers/tambo-stubs.d.ts +2 -2
  238. package/esm/providers/tambo-stubs.d.ts.map +1 -1
  239. package/esm/providers/tambo-stubs.js +5 -0
  240. package/esm/providers/tambo-stubs.js.map +1 -1
  241. package/esm/providers/tambo-thread-input-provider.d.ts +1 -0
  242. package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
  243. package/esm/providers/tambo-thread-input-provider.js +3 -3
  244. package/esm/providers/tambo-thread-input-provider.js.map +1 -1
  245. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  246. package/esm/providers/tambo-thread-provider.js.map +1 -1
  247. package/esm/providers/tambo-thread-provider.test.js +24 -28
  248. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  249. package/esm/schema/index.d.ts +6 -0
  250. package/esm/schema/index.d.ts.map +1 -0
  251. package/esm/schema/index.js +6 -0
  252. package/esm/schema/index.js.map +1 -0
  253. package/esm/schema/json-schema.d.ts +35 -0
  254. package/esm/schema/json-schema.d.ts.map +1 -0
  255. package/esm/schema/json-schema.js +98 -0
  256. package/esm/schema/json-schema.js.map +1 -0
  257. package/esm/schema/schema.d.ts +66 -0
  258. package/esm/schema/schema.d.ts.map +1 -0
  259. package/esm/schema/schema.js +182 -0
  260. package/esm/schema/schema.js.map +1 -0
  261. package/esm/schema/schema.test.d.ts +2 -0
  262. package/esm/schema/schema.test.d.ts.map +1 -0
  263. package/esm/schema/schema.test.js +39 -0
  264. package/esm/schema/schema.test.js.map +1 -0
  265. package/esm/schema/standard-schema.d.ts +21 -0
  266. package/esm/schema/standard-schema.d.ts.map +1 -0
  267. package/esm/schema/standard-schema.js +34 -0
  268. package/esm/schema/standard-schema.js.map +1 -0
  269. package/esm/schema/validate.d.ts +14 -0
  270. package/esm/schema/validate.d.ts.map +1 -0
  271. package/esm/schema/validate.js +145 -0
  272. package/esm/schema/validate.js.map +1 -0
  273. package/esm/schema/validate.test.d.ts +2 -0
  274. package/esm/schema/validate.test.d.ts.map +1 -0
  275. package/esm/schema/validate.test.js +126 -0
  276. package/esm/schema/validate.test.js.map +1 -0
  277. package/esm/schema/zod.d.ts +54 -0
  278. package/esm/schema/zod.d.ts.map +1 -0
  279. package/esm/schema/zod.js +136 -0
  280. package/esm/schema/zod.js.map +1 -0
  281. package/esm/testing/tools.d.ts +29 -15
  282. package/esm/testing/tools.d.ts.map +1 -1
  283. package/esm/testing/tools.js +62 -16
  284. package/esm/testing/tools.js.map +1 -1
  285. package/esm/util/generate-component.d.ts.map +1 -1
  286. package/esm/util/generate-component.js +3 -3
  287. package/esm/util/generate-component.js.map +1 -1
  288. package/esm/util/mcp-server-utils.d.ts +23 -0
  289. package/esm/util/mcp-server-utils.d.ts.map +1 -0
  290. package/esm/util/mcp-server-utils.js +102 -0
  291. package/esm/util/mcp-server-utils.js.map +1 -0
  292. package/esm/util/mcp-server-utils.test.d.ts +2 -0
  293. package/esm/util/mcp-server-utils.test.d.ts.map +1 -0
  294. package/esm/util/mcp-server-utils.test.js +285 -0
  295. package/esm/util/mcp-server-utils.test.js.map +1 -0
  296. package/esm/util/message-builder.d.ts +2 -1
  297. package/esm/util/message-builder.d.ts.map +1 -1
  298. package/esm/util/message-builder.js +54 -36
  299. package/esm/util/message-builder.js.map +1 -1
  300. package/esm/util/message-builder.test.js +500 -13
  301. package/esm/util/message-builder.test.js.map +1 -1
  302. package/esm/util/registry-validators.d.ts +26 -0
  303. package/esm/util/registry-validators.d.ts.map +1 -0
  304. package/esm/util/registry-validators.js +100 -0
  305. package/esm/util/registry-validators.js.map +1 -0
  306. package/esm/util/registry-validators.test.d.ts +2 -0
  307. package/esm/util/registry-validators.test.d.ts.map +1 -0
  308. package/esm/util/registry-validators.test.js +233 -0
  309. package/esm/util/registry-validators.test.js.map +1 -0
  310. package/esm/util/registry.d.ts +35 -7
  311. package/esm/util/registry.d.ts.map +1 -1
  312. package/esm/util/registry.js +57 -73
  313. package/esm/util/registry.js.map +1 -1
  314. package/esm/util/registry.test.d.ts +2 -0
  315. package/esm/util/registry.test.d.ts.map +1 -0
  316. package/esm/util/registry.test.js +169 -0
  317. package/esm/util/registry.test.js.map +1 -0
  318. package/esm/util/resource-validators.d.ts +16 -0
  319. package/esm/util/resource-validators.d.ts.map +1 -0
  320. package/esm/util/resource-validators.js +30 -0
  321. package/esm/util/resource-validators.js.map +1 -0
  322. package/esm/util/tool-caller.d.ts +2 -2
  323. package/esm/util/tool-caller.d.ts.map +1 -1
  324. package/esm/util/tool-caller.js +12 -4
  325. package/esm/util/tool-caller.js.map +1 -1
  326. package/package.json +13 -8
  327. package/dist/providers/hoc/with-tambo-interactable.d.ts.map +0 -1
  328. package/dist/providers/hoc/with-tambo-interactable.js.map +0 -1
  329. package/dist/util/validate-zod-schema.d.ts +0 -10
  330. package/dist/util/validate-zod-schema.d.ts.map +0 -1
  331. package/dist/util/validate-zod-schema.js +0 -100
  332. package/dist/util/validate-zod-schema.js.map +0 -1
  333. package/dist/util/validate-zod-schema.test.d.ts +0 -2
  334. package/dist/util/validate-zod-schema.test.d.ts.map +0 -1
  335. package/dist/util/validate-zod-schema.test.js +0 -96
  336. package/dist/util/validate-zod-schema.test.js.map +0 -1
  337. package/esm/providers/hoc/with-tambo-interactable.d.ts.map +0 -1
  338. package/esm/providers/hoc/with-tambo-interactable.js.map +0 -1
  339. package/esm/util/validate-zod-schema.d.ts +0 -10
  340. package/esm/util/validate-zod-schema.d.ts.map +0 -1
  341. package/esm/util/validate-zod-schema.js +0 -97
  342. package/esm/util/validate-zod-schema.js.map +0 -1
  343. package/esm/util/validate-zod-schema.test.d.ts +0 -2
  344. package/esm/util/validate-zod-schema.test.d.ts.map +0 -1
  345. package/esm/util/validate-zod-schema.test.js +0 -94
  346. package/esm/util/validate-zod-schema.test.js.map +0 -1
@@ -10,7 +10,7 @@ describe("buildMessageContent", () => {
10
10
  ...overrides,
11
11
  });
12
12
  it("should build content with text only", () => {
13
- const result = buildMessageContent("Hello world", []);
13
+ const result = buildMessageContent("Hello world", [], {});
14
14
  expect(result).toEqual([
15
15
  {
16
16
  type: "text",
@@ -22,7 +22,7 @@ describe("buildMessageContent", () => {
22
22
  const image = createMockStagedImage({
23
23
  dataUrl: "data:image/png;base64,abc123",
24
24
  });
25
- const result = buildMessageContent("", [image]);
25
+ const result = buildMessageContent("", [image], {});
26
26
  expect(result).toEqual([
27
27
  {
28
28
  type: "image_url",
@@ -43,7 +43,7 @@ describe("buildMessageContent", () => {
43
43
  dataUrl: "data:image/jpeg;base64,def456",
44
44
  }),
45
45
  ];
46
- const result = buildMessageContent("Check these images:", images);
46
+ const result = buildMessageContent("Check these images:", images, {});
47
47
  expect(result).toEqual([
48
48
  {
49
49
  type: "text",
@@ -63,18 +63,18 @@ describe("buildMessageContent", () => {
63
63
  },
64
64
  ]);
65
65
  });
66
- it("should trim whitespace from text", () => {
67
- const result = buildMessageContent(" Hello world ", []);
66
+ it("should preserve leading and trailing whitespace in text", () => {
67
+ const result = buildMessageContent(" Hello world ", [], {});
68
68
  expect(result).toEqual([
69
69
  {
70
70
  type: "text",
71
- text: "Hello world",
71
+ text: " Hello world ",
72
72
  },
73
73
  ]);
74
74
  });
75
75
  it("should skip empty text but keep images", () => {
76
76
  const image = createMockStagedImage();
77
- const result = buildMessageContent(" ", [image]);
77
+ const result = buildMessageContent(" ", [image], {});
78
78
  expect(result).toEqual([
79
79
  {
80
80
  type: "image_url",
@@ -102,7 +102,7 @@ describe("buildMessageContent", () => {
102
102
  dataUrl: "data:image/gif;base64,photo3data",
103
103
  }),
104
104
  ];
105
- const result = buildMessageContent("Multiple images:", images);
105
+ const result = buildMessageContent("Multiple images:", images, {});
106
106
  expect(result).toHaveLength(4); // 1 text + 3 images
107
107
  expect(result[0]).toEqual({
108
108
  type: "text",
@@ -129,17 +129,17 @@ describe("buildMessageContent", () => {
129
129
  });
130
130
  it("should throw error when no content provided", () => {
131
131
  expect(() => {
132
- buildMessageContent("", []);
132
+ buildMessageContent("", [], {});
133
133
  }).toThrow("Message must contain text or images");
134
134
  });
135
135
  it("should throw error when only whitespace provided", () => {
136
136
  expect(() => {
137
- buildMessageContent(" \n\t ", []);
137
+ buildMessageContent(" \n\t ", [], {});
138
138
  }).toThrow("Message must contain text or images");
139
139
  });
140
140
  it("should return correct content type structure", () => {
141
141
  const image = createMockStagedImage();
142
- const result = buildMessageContent("Test", [image]);
142
+ const result = buildMessageContent("Test", [image], {});
143
143
  // Verify the structure matches ChatCompletionContentPart interface
144
144
  result.forEach((part) => {
145
145
  expect(part).toHaveProperty("type");
@@ -156,7 +156,7 @@ describe("buildMessageContent", () => {
156
156
  });
157
157
  });
158
158
  it("should handle edge case with empty array but valid text", () => {
159
- const result = buildMessageContent("Just text", []);
159
+ const result = buildMessageContent("Just text", [], {});
160
160
  expect(result).toHaveLength(1);
161
161
  expect(result[0]).toEqual({
162
162
  type: "text",
@@ -174,7 +174,7 @@ describe("buildMessageContent", () => {
174
174
  dataUrl: "data:image/png;base64,second",
175
175
  }),
176
176
  ];
177
- const result = buildMessageContent("Text content", images);
177
+ const result = buildMessageContent("Text content", images, {});
178
178
  expect(result[0].type).toBe("text");
179
179
  expect(result[1].type).toBe("image_url");
180
180
  expect(result[2].type).toBe("image_url");
@@ -185,5 +185,492 @@ describe("buildMessageContent", () => {
185
185
  expect(result[2].image_url?.url).toBe("data:image/png;base64,second");
186
186
  }
187
187
  });
188
+ describe("resource parsing", () => {
189
+ it("should parse a single resource reference", () => {
190
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1", [], {});
191
+ expect(result).toEqual([
192
+ {
193
+ type: "text",
194
+ text: "Check ",
195
+ },
196
+ {
197
+ type: "resource",
198
+ resource: {
199
+ uri: "tambo:test://static/resource/1",
200
+ },
201
+ },
202
+ ]);
203
+ });
204
+ it("should parse resource reference at the start of text", () => {
205
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1 check this", [], {});
206
+ expect(result).toEqual([
207
+ {
208
+ type: "resource",
209
+ resource: {
210
+ uri: "tambo:test://static/resource/1",
211
+ },
212
+ },
213
+ {
214
+ type: "text",
215
+ text: " check this",
216
+ },
217
+ ]);
218
+ });
219
+ it("should parse resource reference at the end of text", () => {
220
+ const result = buildMessageContent("Check this @tambo-1hfs429:tambo:test://static/resource/1", [], {});
221
+ expect(result).toEqual([
222
+ {
223
+ type: "text",
224
+ text: "Check this ",
225
+ },
226
+ {
227
+ type: "resource",
228
+ resource: {
229
+ uri: "tambo:test://static/resource/1",
230
+ },
231
+ },
232
+ ]);
233
+ });
234
+ it("should parse resource reference with name from resourceNames map", () => {
235
+ const resourceNames = {
236
+ "tambo-1hfs429:tambo:test://static/resource/1": "Documentation.pdf",
237
+ };
238
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1", [], resourceNames);
239
+ expect(result).toEqual([
240
+ {
241
+ type: "text",
242
+ text: "Check ",
243
+ },
244
+ {
245
+ type: "resource",
246
+ resource: {
247
+ uri: "tambo:test://static/resource/1",
248
+ name: "Documentation.pdf",
249
+ },
250
+ },
251
+ ]);
252
+ });
253
+ it("should parse resource reference without name when not in resourceNames map", () => {
254
+ const resourceNames = {
255
+ "other-server:other-uri": "Other Resource",
256
+ };
257
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1", [], resourceNames);
258
+ expect(result).toEqual([
259
+ {
260
+ type: "text",
261
+ text: "Check ",
262
+ },
263
+ {
264
+ type: "resource",
265
+ resource: {
266
+ uri: "tambo:test://static/resource/1",
267
+ },
268
+ },
269
+ ]);
270
+ });
271
+ it("should parse multiple resource references", () => {
272
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1 and @tambo-1hfs429:tambo:test://static/resource/2", [], {});
273
+ expect(result).toEqual([
274
+ {
275
+ type: "text",
276
+ text: "Check ",
277
+ },
278
+ {
279
+ type: "resource",
280
+ resource: {
281
+ uri: "tambo:test://static/resource/1",
282
+ },
283
+ },
284
+ {
285
+ type: "text",
286
+ text: " and ",
287
+ },
288
+ {
289
+ type: "resource",
290
+ resource: {
291
+ uri: "tambo:test://static/resource/2",
292
+ },
293
+ },
294
+ ]);
295
+ });
296
+ it("should preserve whitespace between consecutive resource references", () => {
297
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1 @tambo-1hfs429:tambo:test://static/resource/2", [], {});
298
+ expect(result).toEqual([
299
+ {
300
+ type: "resource",
301
+ resource: {
302
+ uri: "tambo:test://static/resource/1",
303
+ },
304
+ },
305
+ {
306
+ type: "text",
307
+ text: " ",
308
+ },
309
+ {
310
+ type: "resource",
311
+ resource: {
312
+ uri: "tambo:test://static/resource/2",
313
+ },
314
+ },
315
+ ]);
316
+ });
317
+ it("should parse resources with text before, between, and after", () => {
318
+ const result = buildMessageContent("Before @tambo-1hfs429:tambo:test://static/resource/1 middle @linear:file://path/to/file.txt after", [], {});
319
+ expect(result).toEqual([
320
+ {
321
+ type: "text",
322
+ text: "Before ",
323
+ },
324
+ {
325
+ type: "resource",
326
+ resource: {
327
+ uri: "tambo:test://static/resource/1",
328
+ },
329
+ },
330
+ {
331
+ type: "text",
332
+ text: " middle ",
333
+ },
334
+ {
335
+ type: "resource",
336
+ resource: {
337
+ uri: "file://path/to/file.txt",
338
+ },
339
+ },
340
+ {
341
+ type: "text",
342
+ text: " after",
343
+ },
344
+ ]);
345
+ });
346
+ it("should parse resources from different server keys", () => {
347
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1 and @linear:linear://issue/123", [], {});
348
+ expect(result).toEqual([
349
+ {
350
+ type: "resource",
351
+ resource: {
352
+ uri: "tambo:test://static/resource/1",
353
+ },
354
+ },
355
+ {
356
+ type: "text",
357
+ text: " and ",
358
+ },
359
+ {
360
+ type: "resource",
361
+ resource: {
362
+ uri: "linear://issue/123",
363
+ },
364
+ },
365
+ ]);
366
+ });
367
+ it("should parse resources with various URI formats and preserve whitespace", () => {
368
+ const result = buildMessageContent("@server1:file:///path/to/file.txt @server2:https://example.com/doc.pdf @server3:s3://bucket/key.json", [], {});
369
+ expect(result).toEqual([
370
+ {
371
+ type: "resource",
372
+ resource: {
373
+ uri: "file:///path/to/file.txt",
374
+ },
375
+ },
376
+ {
377
+ type: "text",
378
+ text: " ",
379
+ },
380
+ {
381
+ type: "resource",
382
+ resource: {
383
+ uri: "https://example.com/doc.pdf",
384
+ },
385
+ },
386
+ {
387
+ type: "text",
388
+ text: " ",
389
+ },
390
+ {
391
+ type: "resource",
392
+ resource: {
393
+ uri: "s3://bucket/key.json",
394
+ },
395
+ },
396
+ ]);
397
+ });
398
+ it("should parse resources with hyphens in server key", () => {
399
+ const result = buildMessageContent("@my-server-123:file:///path/to/file.txt", [], {});
400
+ expect(result).toEqual([
401
+ {
402
+ type: "resource",
403
+ resource: {
404
+ uri: "file:///path/to/file.txt",
405
+ },
406
+ },
407
+ ]);
408
+ });
409
+ it("should parse resources with numbers in server key", () => {
410
+ const result = buildMessageContent("@server123:tambo:test://static/resource/1", [], {});
411
+ expect(result).toEqual([
412
+ {
413
+ type: "resource",
414
+ resource: {
415
+ uri: "tambo:test://static/resource/1",
416
+ },
417
+ },
418
+ ]);
419
+ });
420
+ it("should preserve whitespace in text segments around resource references", () => {
421
+ const result = buildMessageContent(" Before @tambo-1hfs429:tambo:test://static/resource/1 After ", [], {});
422
+ expect(result).toEqual([
423
+ {
424
+ type: "text",
425
+ text: " Before ",
426
+ },
427
+ {
428
+ type: "resource",
429
+ resource: {
430
+ uri: "tambo:test://static/resource/1",
431
+ },
432
+ },
433
+ {
434
+ type: "text",
435
+ text: " After ",
436
+ },
437
+ ]);
438
+ });
439
+ it("should handle resource with only whitespace text segments", () => {
440
+ const result = buildMessageContent(" @tambo-1hfs429:tambo:test://static/resource/1 ", [], {});
441
+ expect(result).toEqual([
442
+ {
443
+ type: "text",
444
+ text: " ",
445
+ },
446
+ {
447
+ type: "resource",
448
+ resource: {
449
+ uri: "tambo:test://static/resource/1",
450
+ },
451
+ },
452
+ {
453
+ type: "text",
454
+ text: " ",
455
+ },
456
+ ]);
457
+ });
458
+ it("should preserve newlines and spaces around resource references", () => {
459
+ const result = buildMessageContent("\n @tambo-1hfs429:tambo:test://static/resource/1 text", [], {});
460
+ expect(result).toEqual([
461
+ {
462
+ type: "text",
463
+ text: "\n ",
464
+ },
465
+ {
466
+ type: "resource",
467
+ resource: {
468
+ uri: "tambo:test://static/resource/1",
469
+ },
470
+ },
471
+ {
472
+ type: "text",
473
+ text: " text",
474
+ },
475
+ ]);
476
+ });
477
+ it("should parse resource-only message without text", () => {
478
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1", [], {});
479
+ expect(result).toEqual([
480
+ {
481
+ type: "resource",
482
+ resource: {
483
+ uri: "tambo:test://static/resource/1",
484
+ },
485
+ },
486
+ ]);
487
+ });
488
+ it("should parse multiple resources with names", () => {
489
+ const resourceNames = {
490
+ "tambo-1hfs429:tambo:test://static/resource/1": "First Resource",
491
+ "tambo-1hfs429:tambo:test://static/resource/2": "Second Resource",
492
+ };
493
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1 and @tambo-1hfs429:tambo:test://static/resource/2", [], resourceNames);
494
+ expect(result).toEqual([
495
+ {
496
+ type: "text",
497
+ text: "Check ",
498
+ },
499
+ {
500
+ type: "resource",
501
+ resource: {
502
+ uri: "tambo:test://static/resource/1",
503
+ name: "First Resource",
504
+ },
505
+ },
506
+ {
507
+ type: "text",
508
+ text: " and ",
509
+ },
510
+ {
511
+ type: "resource",
512
+ resource: {
513
+ uri: "tambo:test://static/resource/2",
514
+ name: "Second Resource",
515
+ },
516
+ },
517
+ ]);
518
+ });
519
+ it("should parse resources mixed with images", () => {
520
+ const images = [
521
+ createMockStagedImage({
522
+ id: "img1",
523
+ dataUrl: "data:image/png;base64,abc123",
524
+ }),
525
+ ];
526
+ const result = buildMessageContent("Check @tambo-1hfs429:tambo:test://static/resource/1", images, {});
527
+ expect(result).toEqual([
528
+ {
529
+ type: "text",
530
+ text: "Check ",
531
+ },
532
+ {
533
+ type: "resource",
534
+ resource: {
535
+ uri: "tambo:test://static/resource/1",
536
+ },
537
+ },
538
+ {
539
+ type: "image_url",
540
+ image_url: {
541
+ url: "data:image/png;base64,abc123",
542
+ },
543
+ },
544
+ ]);
545
+ });
546
+ it("should parse resources and images with proper ordering", () => {
547
+ const images = [
548
+ createMockStagedImage({
549
+ id: "img1",
550
+ dataUrl: "data:image/png;base64,img1",
551
+ }),
552
+ createMockStagedImage({
553
+ id: "img2",
554
+ dataUrl: "data:image/jpeg;base64,img2",
555
+ }),
556
+ ];
557
+ const result = buildMessageContent("Text @tambo-1hfs429:tambo:test://static/resource/1 more text", images, {});
558
+ expect(result).toEqual([
559
+ {
560
+ type: "text",
561
+ text: "Text ",
562
+ },
563
+ {
564
+ type: "resource",
565
+ resource: {
566
+ uri: "tambo:test://static/resource/1",
567
+ },
568
+ },
569
+ {
570
+ type: "text",
571
+ text: " more text",
572
+ },
573
+ {
574
+ type: "image_url",
575
+ image_url: {
576
+ url: "data:image/png;base64,img1",
577
+ },
578
+ },
579
+ {
580
+ type: "image_url",
581
+ image_url: {
582
+ url: "data:image/jpeg;base64,img2",
583
+ },
584
+ },
585
+ ]);
586
+ });
587
+ it("should parse resource reference with URI containing colons", () => {
588
+ const result = buildMessageContent("@server:http://example.com:8080/path", [], {});
589
+ expect(result).toEqual([
590
+ {
591
+ type: "resource",
592
+ resource: {
593
+ uri: "http://example.com:8080/path",
594
+ },
595
+ },
596
+ ]);
597
+ });
598
+ it("should parse resource reference with URI containing special characters", () => {
599
+ const result = buildMessageContent("@server:file:///path/to/file%20with%20spaces.txt", [], {});
600
+ expect(result).toEqual([
601
+ {
602
+ type: "resource",
603
+ resource: {
604
+ uri: "file:///path/to/file%20with%20spaces.txt",
605
+ },
606
+ },
607
+ ]);
608
+ });
609
+ it("should not parse @ symbol without server key and colon", () => {
610
+ const result = buildMessageContent("Mention @user but not a resource", [], {});
611
+ expect(result).toEqual([
612
+ {
613
+ type: "text",
614
+ text: "Mention @user but not a resource",
615
+ },
616
+ ]);
617
+ });
618
+ it("should not parse malformed resource reference missing colon", () => {
619
+ const result = buildMessageContent("@serverkey-missing-colon resource", [], {});
620
+ expect(result).toEqual([
621
+ {
622
+ type: "text",
623
+ text: "@serverkey-missing-colon resource",
624
+ },
625
+ ]);
626
+ });
627
+ it("should not parse resource reference with space before colon", () => {
628
+ const result = buildMessageContent("@server key :uri", [], {});
629
+ expect(result).toEqual([
630
+ {
631
+ type: "text",
632
+ text: "@server key :uri",
633
+ },
634
+ ]);
635
+ });
636
+ it("should preserve multiple whitespace characters between consecutive resources", () => {
637
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1 @tambo-1hfs429:tambo:test://static/resource/2", [], {});
638
+ expect(result).toEqual([
639
+ {
640
+ type: "resource",
641
+ resource: {
642
+ uri: "tambo:test://static/resource/1",
643
+ },
644
+ },
645
+ {
646
+ type: "text",
647
+ text: " ",
648
+ },
649
+ {
650
+ type: "resource",
651
+ resource: {
652
+ uri: "tambo:test://static/resource/2",
653
+ },
654
+ },
655
+ ]);
656
+ });
657
+ it("should parse resource with only URI and no surrounding text", () => {
658
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1", [], {});
659
+ expect(result).toEqual([
660
+ {
661
+ type: "resource",
662
+ resource: {
663
+ uri: "tambo:test://static/resource/1",
664
+ },
665
+ },
666
+ ]);
667
+ });
668
+ it("should throw error when only resources with empty text segments", () => {
669
+ // This should work - resources alone should be valid
670
+ const result = buildMessageContent("@tambo-1hfs429:tambo:test://static/resource/1", [], {});
671
+ expect(result.length).toBeGreaterThan(0);
672
+ expect(result[0].type).toBe("resource");
673
+ });
674
+ });
188
675
  });
189
676
  //# sourceMappingURL=message-builder.test.js.map