@tambo-ai/react 1.1.0 → 1.2.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 (457) hide show
  1. package/dist/context-helpers/current-interactables-context-helper.d.ts +16 -2
  2. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  3. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
  4. package/dist/context-helpers/current-interactables-context-helper.test.d.ts +2 -0
  5. package/dist/context-helpers/current-interactables-context-helper.test.d.ts.map +1 -0
  6. package/dist/context-helpers/current-interactables-context-helper.test.js +70 -0
  7. package/dist/context-helpers/current-interactables-context-helper.test.js.map +1 -0
  8. package/dist/mcp/elicitation.d.ts +3 -37
  9. package/dist/mcp/elicitation.d.ts.map +1 -1
  10. package/dist/mcp/elicitation.js +7 -24
  11. package/dist/mcp/elicitation.js.map +1 -1
  12. package/dist/mcp/index.d.ts +4 -4
  13. package/dist/mcp/index.d.ts.map +1 -1
  14. package/dist/mcp/index.js +2 -2
  15. package/dist/mcp/index.js.map +1 -1
  16. package/dist/mcp/mcp-client.test.js +17 -17
  17. package/dist/mcp/mcp-client.test.js.map +1 -1
  18. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  19. package/dist/mcp/mcp-hooks.js +8 -5
  20. package/dist/mcp/mcp-hooks.js.map +1 -1
  21. package/dist/mcp/mcp-hooks.test.js +30 -29
  22. package/dist/mcp/mcp-hooks.test.js.map +1 -1
  23. package/dist/mcp/tambo-mcp-provider.d.ts +6 -9
  24. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  25. package/dist/mcp/tambo-mcp-provider.js +9 -13
  26. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  27. package/dist/mcp/tambo-mcp-provider.test.js +26 -25
  28. package/dist/mcp/tambo-mcp-provider.test.js.map +1 -1
  29. package/dist/mcp/use-mcp-servers.test.js +2 -1
  30. package/dist/mcp/use-mcp-servers.test.js.map +1 -1
  31. package/dist/model/component-metadata.d.ts +7 -372
  32. package/dist/model/component-metadata.d.ts.map +1 -1
  33. package/dist/model/component-metadata.js.map +1 -1
  34. package/dist/model/validate-input.test.d.ts +2 -0
  35. package/dist/model/validate-input.test.d.ts.map +1 -0
  36. package/dist/model/validate-input.test.js +38 -0
  37. package/dist/model/validate-input.test.js.map +1 -0
  38. package/dist/providers/tambo-interactable-provider.d.ts +7 -7
  39. package/dist/providers/tambo-registry-provider.d.ts +1 -1
  40. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  41. package/dist/providers/tambo-registry-provider.js.map +1 -1
  42. package/dist/providers/tambo-registry-schema-compat.test.js +4 -4
  43. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  44. package/dist/schema/index.d.ts +2 -4
  45. package/dist/schema/index.d.ts.map +1 -1
  46. package/dist/schema/index.js +9 -11
  47. package/dist/schema/index.js.map +1 -1
  48. package/dist/schema/json-schema.d.ts +1 -17
  49. package/dist/schema/json-schema.d.ts.map +1 -1
  50. package/dist/schema/json-schema.js +5 -69
  51. package/dist/schema/json-schema.js.map +1 -1
  52. package/dist/schema/schema.test.js +24 -25
  53. package/dist/schema/schema.test.js.map +1 -1
  54. package/dist/schema/standard-schema.test.js +25 -25
  55. package/dist/schema/standard-schema.test.js.map +1 -1
  56. package/dist/schema/validate.test.js +33 -33
  57. package/dist/schema/validate.test.js.map +1 -1
  58. package/dist/testing/tools.d.ts +4 -4
  59. package/dist/testing/tools.test.d.ts +2 -0
  60. package/dist/testing/tools.test.d.ts.map +1 -0
  61. package/dist/testing/tools.test.js +60 -0
  62. package/dist/testing/tools.test.js.map +1 -0
  63. package/dist/util/mcp-server-utils.d.ts +1 -1
  64. package/dist/util/mcp-server-utils.d.ts.map +1 -1
  65. package/dist/util/mcp-server-utils.js +4 -4
  66. package/dist/util/mcp-server-utils.js.map +1 -1
  67. package/dist/util/mcp-server-utils.test.js +27 -27
  68. package/dist/util/mcp-server-utils.test.js.map +1 -1
  69. package/dist/util/registry.js +1 -1
  70. package/dist/util/registry.js.map +1 -1
  71. package/dist/util/resource-content-resolver.js +5 -5
  72. package/dist/util/resource-content-resolver.js.map +1 -1
  73. package/dist/util/resource-content-resolver.test.js +6 -6
  74. package/dist/util/resource-content-resolver.test.js.map +1 -1
  75. package/dist/util/tool-caller.test.d.ts +2 -0
  76. package/dist/util/tool-caller.test.d.ts.map +1 -0
  77. package/dist/util/tool-caller.test.js +71 -0
  78. package/dist/util/tool-caller.test.js.map +1 -0
  79. package/dist/v1/__tests__/v1-interactables.test.js +1 -0
  80. package/dist/v1/__tests__/v1-interactables.test.js.map +1 -1
  81. package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts +1 -1
  82. package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
  83. package/dist/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
  84. package/dist/v1/hooks/use-tambo-v1-component-state.js +2 -2
  85. package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
  86. package/dist/v1/hooks/use-tambo-v1-component-state.test.js +1 -1
  87. package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
  88. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +1 -1
  89. package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  90. package/dist/v1/hooks/use-tambo-v1-send-message.js +17 -17
  91. package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  92. package/dist/v1/hooks/use-tambo-v1-send-message.test.js +1 -1
  93. package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  94. package/dist/v1/hooks/use-tambo-v1-stream-status.js +2 -2
  95. package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
  96. package/dist/v1/hooks/use-tambo-v1-stream-status.test.js +9 -5
  97. package/dist/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
  98. package/dist/v1/hooks/use-tambo-v1-suggestions.js +2 -2
  99. package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
  100. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +1 -0
  101. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
  102. package/dist/v1/hooks/use-tambo-v1.d.ts +7 -6
  103. package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -1
  104. package/dist/v1/hooks/use-tambo-v1.js +2 -2
  105. package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
  106. package/dist/v1/hooks/use-tambo-v1.test.js +23 -23
  107. package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
  108. package/dist/v1/index.d.ts +6 -6
  109. package/dist/v1/index.d.ts.map +1 -1
  110. package/dist/v1/index.js +2 -2
  111. package/dist/v1/index.js.map +1 -1
  112. package/dist/v1/providers/tambo-v1-provider.d.ts +2 -1
  113. package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  114. package/dist/v1/providers/tambo-v1-provider.js +2 -0
  115. package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
  116. package/dist/v1/providers/tambo-v1-stream-context.d.ts +2 -2
  117. package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  118. package/dist/v1/providers/tambo-v1-stream-context.js +9 -9
  119. package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
  120. package/dist/v1/providers/tambo-v1-stream-context.test.js +35 -0
  121. package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  122. package/dist/v1/providers/tambo-v1-stub-provider.d.ts +1 -1
  123. package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
  124. package/dist/v1/providers/tambo-v1-stub-provider.js +1 -1
  125. package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
  126. package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
  127. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +1 -1
  128. package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
  129. package/dist/v1/providers/tambo-v1-thread-input-provider.js +2 -2
  130. package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
  131. package/dist/v1/types/event.test.js +13 -13
  132. package/dist/v1/types/event.test.js.map +1 -1
  133. package/dist/v1/types/message.d.ts +12 -109
  134. package/dist/v1/types/message.d.ts.map +1 -1
  135. package/dist/v1/types/message.js +0 -7
  136. package/dist/v1/types/message.js.map +1 -1
  137. package/dist/v1/utils/event-accumulator.test.js +183 -184
  138. package/dist/v1/utils/event-accumulator.test.js.map +1 -1
  139. package/dist/v1/utils/json-patch.test.js +4 -4
  140. package/dist/v1/utils/json-patch.test.js.map +1 -1
  141. package/dist/v1/utils/keyed-throttle.test.js +12 -12
  142. package/dist/v1/utils/keyed-throttle.test.js.map +1 -1
  143. package/dist/v1/utils/registry-conversion.test.js +13 -13
  144. package/dist/v1/utils/registry-conversion.test.js.map +1 -1
  145. package/dist/v1/utils/stream-handler.test.js +5 -5
  146. package/dist/v1/utils/stream-handler.test.js.map +1 -1
  147. package/dist/v1/utils/tool-call-tracker.test.js +15 -9
  148. package/dist/v1/utils/tool-call-tracker.test.js.map +1 -1
  149. package/dist/v1/utils/tool-executor.test.js +25 -26
  150. package/dist/v1/utils/tool-executor.test.js.map +1 -1
  151. package/dist/v1/utils/unstrictify.test.js +16 -16
  152. package/dist/v1/utils/unstrictify.test.js.map +1 -1
  153. package/esm/context-helpers/current-interactables-context-helper.d.ts +16 -2
  154. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  155. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  156. package/esm/context-helpers/current-interactables-context-helper.test.d.ts +2 -0
  157. package/esm/context-helpers/current-interactables-context-helper.test.d.ts.map +1 -0
  158. package/esm/context-helpers/current-interactables-context-helper.test.js +68 -0
  159. package/esm/context-helpers/current-interactables-context-helper.test.js.map +1 -0
  160. package/esm/mcp/elicitation.d.ts +3 -37
  161. package/esm/mcp/elicitation.d.ts.map +1 -1
  162. package/esm/mcp/elicitation.js +4 -24
  163. package/esm/mcp/elicitation.js.map +1 -1
  164. package/esm/mcp/index.d.ts +4 -4
  165. package/esm/mcp/index.d.ts.map +1 -1
  166. package/esm/mcp/index.js +1 -1
  167. package/esm/mcp/index.js.map +1 -1
  168. package/esm/mcp/mcp-client.test.js +1 -1
  169. package/esm/mcp/mcp-client.test.js.map +1 -1
  170. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  171. package/esm/mcp/mcp-hooks.js +4 -1
  172. package/esm/mcp/mcp-hooks.js.map +1 -1
  173. package/esm/mcp/mcp-hooks.test.js +3 -2
  174. package/esm/mcp/mcp-hooks.test.js.map +1 -1
  175. package/esm/mcp/tambo-mcp-provider.d.ts +6 -9
  176. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  177. package/esm/mcp/tambo-mcp-provider.js +4 -8
  178. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  179. package/esm/mcp/tambo-mcp-provider.test.js +3 -2
  180. package/esm/mcp/tambo-mcp-provider.test.js.map +1 -1
  181. package/esm/mcp/use-mcp-servers.test.js +2 -1
  182. package/esm/mcp/use-mcp-servers.test.js.map +1 -1
  183. package/esm/model/component-metadata.d.ts +7 -372
  184. package/esm/model/component-metadata.d.ts.map +1 -1
  185. package/esm/model/component-metadata.js.map +1 -1
  186. package/esm/model/validate-input.test.d.ts +2 -0
  187. package/esm/model/validate-input.test.d.ts.map +1 -0
  188. package/esm/model/validate-input.test.js +36 -0
  189. package/esm/model/validate-input.test.js.map +1 -0
  190. package/esm/providers/tambo-interactable-provider.d.ts +7 -7
  191. package/esm/providers/tambo-registry-provider.d.ts +1 -1
  192. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  193. package/esm/providers/tambo-registry-provider.js.map +1 -1
  194. package/esm/providers/tambo-registry-schema-compat.test.js +4 -4
  195. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  196. package/esm/schema/index.d.ts +2 -4
  197. package/esm/schema/index.d.ts.map +1 -1
  198. package/esm/schema/index.js +2 -4
  199. package/esm/schema/index.js.map +1 -1
  200. package/esm/schema/json-schema.d.ts +1 -17
  201. package/esm/schema/json-schema.d.ts.map +1 -1
  202. package/esm/schema/json-schema.js +2 -67
  203. package/esm/schema/json-schema.js.map +1 -1
  204. package/esm/schema/schema.test.js +1 -2
  205. package/esm/schema/schema.test.js.map +1 -1
  206. package/esm/schema/standard-schema.test.js +1 -1
  207. package/esm/schema/standard-schema.test.js.map +1 -1
  208. package/esm/schema/validate.test.js +1 -1
  209. package/esm/schema/validate.test.js.map +1 -1
  210. package/esm/testing/tools.d.ts +4 -4
  211. package/esm/testing/tools.test.d.ts +2 -0
  212. package/esm/testing/tools.test.d.ts.map +1 -0
  213. package/esm/testing/tools.test.js +58 -0
  214. package/esm/testing/tools.test.js.map +1 -0
  215. package/esm/util/mcp-server-utils.d.ts +1 -1
  216. package/esm/util/mcp-server-utils.d.ts.map +1 -1
  217. package/esm/util/mcp-server-utils.js +1 -1
  218. package/esm/util/mcp-server-utils.js.map +1 -1
  219. package/esm/util/mcp-server-utils.test.js +1 -1
  220. package/esm/util/mcp-server-utils.test.js.map +1 -1
  221. package/esm/util/registry.js +1 -1
  222. package/esm/util/registry.js.map +1 -1
  223. package/esm/util/resource-content-resolver.js +1 -1
  224. package/esm/util/resource-content-resolver.js.map +1 -1
  225. package/esm/util/resource-content-resolver.test.js +2 -2
  226. package/esm/util/resource-content-resolver.test.js.map +1 -1
  227. package/esm/util/tool-caller.test.d.ts +2 -0
  228. package/esm/util/tool-caller.test.d.ts.map +1 -0
  229. package/esm/util/tool-caller.test.js +69 -0
  230. package/esm/util/tool-caller.test.js.map +1 -0
  231. package/esm/v1/__tests__/v1-interactables.test.js +1 -0
  232. package/esm/v1/__tests__/v1-interactables.test.js.map +1 -1
  233. package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts +1 -1
  234. package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
  235. package/esm/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
  236. package/esm/v1/hooks/use-tambo-v1-component-state.js +1 -1
  237. package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
  238. package/esm/v1/hooks/use-tambo-v1-component-state.test.js +1 -1
  239. package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
  240. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +1 -1
  241. package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
  242. package/esm/v1/hooks/use-tambo-v1-send-message.js +6 -6
  243. package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
  244. package/esm/v1/hooks/use-tambo-v1-send-message.test.js +1 -1
  245. package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
  246. package/esm/v1/hooks/use-tambo-v1-stream-status.js +1 -1
  247. package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
  248. package/esm/v1/hooks/use-tambo-v1-stream-status.test.js +9 -5
  249. package/esm/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
  250. package/esm/v1/hooks/use-tambo-v1-suggestions.js +1 -1
  251. package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
  252. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +1 -0
  253. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
  254. package/esm/v1/hooks/use-tambo-v1.d.ts +7 -6
  255. package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -1
  256. package/esm/v1/hooks/use-tambo-v1.js +1 -1
  257. package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
  258. package/esm/v1/hooks/use-tambo-v1.test.js +22 -22
  259. package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
  260. package/esm/v1/index.d.ts +6 -6
  261. package/esm/v1/index.d.ts.map +1 -1
  262. package/esm/v1/index.js +1 -1
  263. package/esm/v1/index.js.map +1 -1
  264. package/esm/v1/providers/tambo-v1-provider.d.ts +2 -1
  265. package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  266. package/esm/v1/providers/tambo-v1-provider.js +2 -0
  267. package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
  268. package/esm/v1/providers/tambo-v1-stream-context.d.ts +2 -2
  269. package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
  270. package/esm/v1/providers/tambo-v1-stream-context.js +1 -1
  271. package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
  272. package/esm/v1/providers/tambo-v1-stream-context.test.js +35 -0
  273. package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
  274. package/esm/v1/providers/tambo-v1-stub-provider.d.ts +1 -1
  275. package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
  276. package/esm/v1/providers/tambo-v1-stub-provider.js +1 -1
  277. package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
  278. package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
  279. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +1 -1
  280. package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
  281. package/esm/v1/providers/tambo-v1-thread-input-provider.js +1 -1
  282. package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
  283. package/esm/v1/types/event.test.js +1 -1
  284. package/esm/v1/types/event.test.js.map +1 -1
  285. package/esm/v1/types/message.d.ts +12 -109
  286. package/esm/v1/types/message.d.ts.map +1 -1
  287. package/esm/v1/types/message.js +0 -7
  288. package/esm/v1/types/message.js.map +1 -1
  289. package/esm/v1/utils/event-accumulator.test.js +2 -3
  290. package/esm/v1/utils/event-accumulator.test.js.map +1 -1
  291. package/esm/v1/utils/json-patch.test.js +1 -1
  292. package/esm/v1/utils/json-patch.test.js.map +1 -1
  293. package/esm/v1/utils/keyed-throttle.test.js +1 -1
  294. package/esm/v1/utils/keyed-throttle.test.js.map +1 -1
  295. package/esm/v1/utils/registry-conversion.test.js +1 -1
  296. package/esm/v1/utils/registry-conversion.test.js.map +1 -1
  297. package/esm/v1/utils/stream-handler.test.js +1 -1
  298. package/esm/v1/utils/stream-handler.test.js.map +1 -1
  299. package/esm/v1/utils/tool-call-tracker.test.js +9 -3
  300. package/esm/v1/utils/tool-call-tracker.test.js.map +1 -1
  301. package/esm/v1/utils/tool-executor.test.js +1 -2
  302. package/esm/v1/utils/tool-executor.test.js.map +1 -1
  303. package/esm/v1/utils/unstrictify.test.js +1 -1
  304. package/esm/v1/utils/unstrictify.test.js.map +1 -1
  305. package/package.json +10 -11
  306. package/dist/mcp/mcp-client.d.ts +0 -185
  307. package/dist/mcp/mcp-client.d.ts.map +0 -1
  308. package/dist/mcp/mcp-client.js +0 -219
  309. package/dist/mcp/mcp-client.js.map +0 -1
  310. package/dist/mcp/mcp-constants.d.ts +0 -19
  311. package/dist/mcp/mcp-constants.d.ts.map +0 -1
  312. package/dist/mcp/mcp-constants.js +0 -21
  313. package/dist/mcp/mcp-constants.js.map +0 -1
  314. package/dist/model/mcp-server-info.d.ts +0 -76
  315. package/dist/model/mcp-server-info.d.ts.map +0 -1
  316. package/dist/model/mcp-server-info.js +0 -29
  317. package/dist/model/mcp-server-info.js.map +0 -1
  318. package/dist/schema/schema.d.ts +0 -49
  319. package/dist/schema/schema.d.ts.map +0 -1
  320. package/dist/schema/schema.js +0 -129
  321. package/dist/schema/schema.js.map +0 -1
  322. package/dist/schema/standard-schema.d.ts +0 -22
  323. package/dist/schema/standard-schema.d.ts.map +0 -1
  324. package/dist/schema/standard-schema.js +0 -42
  325. package/dist/schema/standard-schema.js.map +0 -1
  326. package/dist/schema/validate.d.ts +0 -14
  327. package/dist/schema/validate.d.ts.map +0 -1
  328. package/dist/schema/validate.js +0 -148
  329. package/dist/schema/validate.js.map +0 -1
  330. package/dist/v1/types/auth.d.ts +0 -24
  331. package/dist/v1/types/auth.d.ts.map +0 -1
  332. package/dist/v1/types/auth.js +0 -3
  333. package/dist/v1/types/auth.js.map +0 -1
  334. package/dist/v1/types/event.d.ts +0 -89
  335. package/dist/v1/types/event.d.ts.map +0 -1
  336. package/dist/v1/types/event.js +0 -57
  337. package/dist/v1/types/event.js.map +0 -1
  338. package/dist/v1/types/thread.d.ts +0 -58
  339. package/dist/v1/types/thread.d.ts.map +0 -1
  340. package/dist/v1/types/thread.js +0 -9
  341. package/dist/v1/types/thread.js.map +0 -1
  342. package/dist/v1/types/tool-choice.d.ts +0 -8
  343. package/dist/v1/types/tool-choice.d.ts.map +0 -1
  344. package/dist/v1/types/tool-choice.js +0 -3
  345. package/dist/v1/types/tool-choice.js.map +0 -1
  346. package/dist/v1/utils/event-accumulator.d.ts +0 -165
  347. package/dist/v1/utils/event-accumulator.d.ts.map +0 -1
  348. package/dist/v1/utils/event-accumulator.js +0 -1277
  349. package/dist/v1/utils/event-accumulator.js.map +0 -1
  350. package/dist/v1/utils/json-patch.d.ts +0 -18
  351. package/dist/v1/utils/json-patch.d.ts.map +0 -1
  352. package/dist/v1/utils/json-patch.js +0 -35
  353. package/dist/v1/utils/json-patch.js.map +0 -1
  354. package/dist/v1/utils/keyed-throttle.d.ts +0 -42
  355. package/dist/v1/utils/keyed-throttle.d.ts.map +0 -1
  356. package/dist/v1/utils/keyed-throttle.js +0 -86
  357. package/dist/v1/utils/keyed-throttle.js.map +0 -1
  358. package/dist/v1/utils/registry-conversion.d.ts +0 -53
  359. package/dist/v1/utils/registry-conversion.d.ts.map +0 -1
  360. package/dist/v1/utils/registry-conversion.js +0 -115
  361. package/dist/v1/utils/registry-conversion.js.map +0 -1
  362. package/dist/v1/utils/stream-handler.d.ts +0 -45
  363. package/dist/v1/utils/stream-handler.d.ts.map +0 -1
  364. package/dist/v1/utils/stream-handler.js +0 -47
  365. package/dist/v1/utils/stream-handler.js.map +0 -1
  366. package/dist/v1/utils/thread-utils.d.ts +0 -16
  367. package/dist/v1/utils/thread-utils.d.ts.map +0 -1
  368. package/dist/v1/utils/thread-utils.js +0 -34
  369. package/dist/v1/utils/thread-utils.js.map +0 -1
  370. package/dist/v1/utils/tool-call-tracker.d.ts +0 -73
  371. package/dist/v1/utils/tool-call-tracker.d.ts.map +0 -1
  372. package/dist/v1/utils/tool-call-tracker.js +0 -180
  373. package/dist/v1/utils/tool-call-tracker.js.map +0 -1
  374. package/dist/v1/utils/tool-executor.d.ts +0 -67
  375. package/dist/v1/utils/tool-executor.d.ts.map +0 -1
  376. package/dist/v1/utils/tool-executor.js +0 -160
  377. package/dist/v1/utils/tool-executor.js.map +0 -1
  378. package/dist/v1/utils/unstrictify.d.ts +0 -32
  379. package/dist/v1/utils/unstrictify.d.ts.map +0 -1
  380. package/dist/v1/utils/unstrictify.js +0 -159
  381. package/dist/v1/utils/unstrictify.js.map +0 -1
  382. package/esm/mcp/mcp-client.d.ts +0 -185
  383. package/esm/mcp/mcp-client.d.ts.map +0 -1
  384. package/esm/mcp/mcp-client.js +0 -216
  385. package/esm/mcp/mcp-client.js.map +0 -1
  386. package/esm/mcp/mcp-constants.d.ts +0 -19
  387. package/esm/mcp/mcp-constants.d.ts.map +0 -1
  388. package/esm/mcp/mcp-constants.js +0 -18
  389. package/esm/mcp/mcp-constants.js.map +0 -1
  390. package/esm/model/mcp-server-info.d.ts +0 -76
  391. package/esm/model/mcp-server-info.d.ts.map +0 -1
  392. package/esm/model/mcp-server-info.js +0 -25
  393. package/esm/model/mcp-server-info.js.map +0 -1
  394. package/esm/schema/schema.d.ts +0 -49
  395. package/esm/schema/schema.d.ts.map +0 -1
  396. package/esm/schema/schema.js +0 -124
  397. package/esm/schema/schema.js.map +0 -1
  398. package/esm/schema/standard-schema.d.ts +0 -22
  399. package/esm/schema/standard-schema.d.ts.map +0 -1
  400. package/esm/schema/standard-schema.js +0 -39
  401. package/esm/schema/standard-schema.js.map +0 -1
  402. package/esm/schema/validate.d.ts +0 -14
  403. package/esm/schema/validate.d.ts.map +0 -1
  404. package/esm/schema/validate.js +0 -145
  405. package/esm/schema/validate.js.map +0 -1
  406. package/esm/v1/types/auth.d.ts +0 -24
  407. package/esm/v1/types/auth.d.ts.map +0 -1
  408. package/esm/v1/types/auth.js +0 -2
  409. package/esm/v1/types/auth.js.map +0 -1
  410. package/esm/v1/types/event.d.ts +0 -89
  411. package/esm/v1/types/event.d.ts.map +0 -1
  412. package/esm/v1/types/event.js +0 -53
  413. package/esm/v1/types/event.js.map +0 -1
  414. package/esm/v1/types/thread.d.ts +0 -58
  415. package/esm/v1/types/thread.d.ts.map +0 -1
  416. package/esm/v1/types/thread.js +0 -8
  417. package/esm/v1/types/thread.js.map +0 -1
  418. package/esm/v1/types/tool-choice.d.ts +0 -8
  419. package/esm/v1/types/tool-choice.d.ts.map +0 -1
  420. package/esm/v1/types/tool-choice.js +0 -2
  421. package/esm/v1/types/tool-choice.js.map +0 -1
  422. package/esm/v1/utils/event-accumulator.d.ts +0 -165
  423. package/esm/v1/utils/event-accumulator.d.ts.map +0 -1
  424. package/esm/v1/utils/event-accumulator.js +0 -1268
  425. package/esm/v1/utils/event-accumulator.js.map +0 -1
  426. package/esm/v1/utils/json-patch.d.ts +0 -18
  427. package/esm/v1/utils/json-patch.d.ts.map +0 -1
  428. package/esm/v1/utils/json-patch.js +0 -32
  429. package/esm/v1/utils/json-patch.js.map +0 -1
  430. package/esm/v1/utils/keyed-throttle.d.ts +0 -42
  431. package/esm/v1/utils/keyed-throttle.d.ts.map +0 -1
  432. package/esm/v1/utils/keyed-throttle.js +0 -83
  433. package/esm/v1/utils/keyed-throttle.js.map +0 -1
  434. package/esm/v1/utils/registry-conversion.d.ts +0 -53
  435. package/esm/v1/utils/registry-conversion.d.ts.map +0 -1
  436. package/esm/v1/utils/registry-conversion.js +0 -109
  437. package/esm/v1/utils/registry-conversion.js.map +0 -1
  438. package/esm/v1/utils/stream-handler.d.ts +0 -45
  439. package/esm/v1/utils/stream-handler.d.ts.map +0 -1
  440. package/esm/v1/utils/stream-handler.js +0 -44
  441. package/esm/v1/utils/stream-handler.js.map +0 -1
  442. package/esm/v1/utils/thread-utils.d.ts +0 -16
  443. package/esm/v1/utils/thread-utils.d.ts.map +0 -1
  444. package/esm/v1/utils/thread-utils.js +0 -31
  445. package/esm/v1/utils/thread-utils.js.map +0 -1
  446. package/esm/v1/utils/tool-call-tracker.d.ts +0 -73
  447. package/esm/v1/utils/tool-call-tracker.d.ts.map +0 -1
  448. package/esm/v1/utils/tool-call-tracker.js +0 -176
  449. package/esm/v1/utils/tool-call-tracker.js.map +0 -1
  450. package/esm/v1/utils/tool-executor.d.ts +0 -67
  451. package/esm/v1/utils/tool-executor.d.ts.map +0 -1
  452. package/esm/v1/utils/tool-executor.js +0 -154
  453. package/esm/v1/utils/tool-executor.js.map +0 -1
  454. package/esm/v1/utils/unstrictify.d.ts +0 -32
  455. package/esm/v1/utils/unstrictify.d.ts.map +0 -1
  456. package/esm/v1/utils/unstrictify.js +0 -155
  457. package/esm/v1/utils/unstrictify.js.map +0 -1
@@ -1,160 +0,0 @@
1
- "use strict";
2
- /**
3
- * Tool Executor
4
- *
5
- * Handles automatic execution of client-side tools when the model
6
- * requests them via `tambo.run.awaiting_input` events.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.executeStreamableToolCall = executeStreamableToolCall;
10
- exports.createThrottledStreamableExecutor = createThrottledStreamableExecutor;
11
- exports.executeClientTool = executeClientTool;
12
- exports.executeAllPendingTools = executeAllPendingTools;
13
- const keyed_throttle_1 = require("./keyed-throttle");
14
- /**
15
- * Execute a streamable tool call during streaming with pre-parsed partial args.
16
- *
17
- * Called on each TOOL_CALL_ARGS event for tools annotated with
18
- * `tamboStreamableHint: true`. Enables incremental UI updates while
19
- * the model is still generating arguments.
20
- *
21
- * Errors are caught silently — streaming tool execution is non-fatal since
22
- * the final execution via `awaiting_input` is what matters.
23
- * @param toolCallId - The tool call ID being accumulated
24
- * @param parsedArgs - Pre-parsed partial JSON args
25
- * @param toolTracker - Tracker holding pending tool call state
26
- * @param toolRegistry - Record of tool name to tool definition
27
- */
28
- async function executeStreamableToolCall(toolCallId, parsedArgs, toolTracker, toolRegistry) {
29
- const accumulating = toolTracker.getAccumulatingToolCall(toolCallId);
30
- if (!accumulating)
31
- return;
32
- const tool = toolRegistry[accumulating.name];
33
- if (!tool?.annotations?.tamboStreamableHint)
34
- return;
35
- try {
36
- await tool.tool(parsedArgs);
37
- }
38
- catch (error) {
39
- console.warn(`[ToolExecutor] Non-fatal error in streamable tool "${accumulating.name}" ` +
40
- `(toolCallId: ${toolCallId}). This likely indicates a bug in the tool ` +
41
- `implementation; fix the tool to avoid repeated warnings.`, error);
42
- }
43
- }
44
- const DEFAULT_STREAMABLE_THROTTLE_MS = 100;
45
- /**
46
- * Creates a throttled wrapper around executeStreamableToolCall.
47
- *
48
- * Each tool call ID gets its own independent leading+trailing throttle via
49
- * {@link createKeyedThrottle}. The first call for a tool ID fires immediately
50
- * (leading edge). Subsequent calls during the cooldown window update the
51
- * stored args. After `delay` ms, if new args arrived, the tool re-executes
52
- * with the latest args (trailing edge). This repeats as long as new args
53
- * keep arriving — roughly one execution per `delay` ms during streaming.
54
- *
55
- * Call `flush()` to force-execute all pending trailing calls and reset to idle.
56
- * @param toolTracker - Tracker holding pending tool call state
57
- * @param toolRegistry - Record of tool name to tool definition
58
- * @param delay - Throttle interval in milliseconds
59
- * @returns Keyed throttle controller (schedule / flush)
60
- */
61
- function createThrottledStreamableExecutor(toolTracker, toolRegistry, delay = DEFAULT_STREAMABLE_THROTTLE_MS) {
62
- return (0, keyed_throttle_1.createKeyedThrottle)((toolCallId, args) => {
63
- void executeStreamableToolCall(toolCallId, args, toolTracker, toolRegistry);
64
- }, delay);
65
- }
66
- /**
67
- * Execute a single client-side tool and return the result.
68
- * @param tool - The tool definition from the registry
69
- * @param toolCallId - The ID of the tool call to respond to
70
- * @param args - The parsed arguments for the tool
71
- * @returns ToolResultContent with the execution result or error
72
- */
73
- async function executeClientTool(tool, toolCallId, args) {
74
- try {
75
- const result = await tool.tool(args);
76
- // Transform result to content if transformer provided
77
- let content;
78
- if (tool.transformToContent) {
79
- // transformToContent may return content parts in beta format
80
- // Convert to content format (TextContent | ResourceContent)
81
- const transformed = await tool.transformToContent(result);
82
- content = transformed.map((part) => {
83
- if (part.type === "text" && "text" in part && part.text) {
84
- return { type: "text", text: part.text };
85
- }
86
- // For other types, stringify as text
87
- return {
88
- type: "text",
89
- text: JSON.stringify(part),
90
- };
91
- });
92
- }
93
- else {
94
- // Default: stringify result as text
95
- content = [
96
- {
97
- type: "text",
98
- text: typeof result === "string" ? result : JSON.stringify(result),
99
- },
100
- ];
101
- }
102
- return {
103
- type: "tool_result",
104
- toolUseId: toolCallId,
105
- content,
106
- };
107
- }
108
- catch (error) {
109
- return {
110
- type: "tool_result",
111
- toolUseId: toolCallId,
112
- isError: true,
113
- content: [
114
- {
115
- type: "text",
116
- text: error instanceof Error ? error.message : "Tool execution failed",
117
- },
118
- ],
119
- };
120
- }
121
- }
122
- /**
123
- * Execute all pending tool calls and return their results.
124
- * Tools are executed sequentially to avoid race conditions when
125
- * tools may have side effects that depend on each other.
126
- * @param toolCalls - Map of tool call IDs to their call details
127
- * @param registry - Registry of tool names to their definitions (Map or Record)
128
- * @returns Array of ToolResultContent for all executed tools
129
- */
130
- async function executeAllPendingTools(toolCalls, registry) {
131
- const results = [];
132
- // Normalize registry to allow lookup regardless of Map or Record
133
- const getTool = (name) => {
134
- if (registry instanceof Map) {
135
- return registry.get(name);
136
- }
137
- return registry[name];
138
- };
139
- for (const [toolCallId, { name, input }] of toolCalls) {
140
- const tool = getTool(name);
141
- if (!tool) {
142
- results.push({
143
- type: "tool_result",
144
- toolUseId: toolCallId,
145
- isError: true,
146
- content: [
147
- {
148
- type: "text",
149
- text: `Tool "${name}" not found in registry`,
150
- },
151
- ],
152
- });
153
- continue;
154
- }
155
- const result = await executeClientTool(tool, toolCallId, input);
156
- results.push(result);
157
- }
158
- return results;
159
- }
160
- //# sourceMappingURL=tool-executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../../../src/v1/utils/tool-executor.ts"],"names":[],"mappings":";AAAA;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AOG;AACI,KAAK,UAAU,sBAAsB,CAC1C,SAAuC,EACvC,QAA4D;IAE5D,MAAM,OAAO,GAAwB,EAAE,CAAC;IAExC,iEAAiE;IACjE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAyB,EAAE;QACtD,IAAI,QAAQ,YAAY,GAAG,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,KAAK,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACtD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,aAAa;gBACnB,SAAS,EAAE,UAAU;gBACrB,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,SAAS,IAAI,yBAAyB;qBAC7C;iBACF;aACF,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Tool Executor\n *\n * Handles automatic execution of client-side tools when the model\n * requests them via `tambo.run.awaiting_input` events.\n */\n\nimport type { TamboTool } from \"../../model/component-metadata\";\nimport type {\n ToolResultContent,\n TextContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\nimport type { ToolCallTracker } from \"./tool-call-tracker\";\nimport { createKeyedThrottle, type KeyedThrottle } from \"./keyed-throttle\";\n\n/**\n * Pending tool call from the stream accumulator\n */\nexport interface PendingToolCall {\n name: string;\n input: Record<string, unknown>;\n}\n\n/**\n * Execute a streamable tool call during streaming with pre-parsed partial args.\n *\n * Called on each TOOL_CALL_ARGS event for tools annotated with\n * `tamboStreamableHint: true`. Enables incremental UI updates while\n * the model is still generating arguments.\n *\n * Errors are caught silently — streaming tool execution is non-fatal since\n * the final execution via `awaiting_input` is what matters.\n * @param toolCallId - The tool call ID being accumulated\n * @param parsedArgs - Pre-parsed partial JSON args\n * @param toolTracker - Tracker holding pending tool call state\n * @param toolRegistry - Record of tool name to tool definition\n */\nexport async function executeStreamableToolCall(\n toolCallId: string,\n parsedArgs: Record<string, unknown>,\n toolTracker: ToolCallTracker,\n toolRegistry: Record<string, TamboTool>,\n): Promise<void> {\n const accumulating = toolTracker.getAccumulatingToolCall(toolCallId);\n if (!accumulating) return;\n\n const tool = toolRegistry[accumulating.name];\n if (!tool?.annotations?.tamboStreamableHint) return;\n\n try {\n await tool.tool(parsedArgs);\n } catch (error) {\n console.warn(\n `[ToolExecutor] Non-fatal error in streamable tool \"${accumulating.name}\" ` +\n `(toolCallId: ${toolCallId}). This likely indicates a bug in the tool ` +\n `implementation; fix the tool to avoid repeated warnings.`,\n error,\n );\n }\n}\n\nconst DEFAULT_STREAMABLE_THROTTLE_MS = 100;\n\n/**\n * Creates a throttled wrapper around executeStreamableToolCall.\n *\n * Each tool call ID gets its own independent leading+trailing throttle via\n * {@link createKeyedThrottle}. The first call for a tool ID fires immediately\n * (leading edge). Subsequent calls during the cooldown window update the\n * stored args. After `delay` ms, if new args arrived, the tool re-executes\n * with the latest args (trailing edge). This repeats as long as new args\n * keep arriving — roughly one execution per `delay` ms during streaming.\n *\n * Call `flush()` to force-execute all pending trailing calls and reset to idle.\n * @param toolTracker - Tracker holding pending tool call state\n * @param toolRegistry - Record of tool name to tool definition\n * @param delay - Throttle interval in milliseconds\n * @returns Keyed throttle controller (schedule / flush)\n */\nexport function createThrottledStreamableExecutor(\n toolTracker: ToolCallTracker,\n toolRegistry: Record<string, TamboTool>,\n delay = DEFAULT_STREAMABLE_THROTTLE_MS,\n): KeyedThrottle<Record<string, unknown>> {\n return createKeyedThrottle<Record<string, unknown>>((toolCallId, args) => {\n void executeStreamableToolCall(toolCallId, args, toolTracker, toolRegistry);\n }, delay);\n}\n\n/**\n * Execute a single client-side tool and return the result.\n * @param tool - The tool definition from the registry\n * @param toolCallId - The ID of the tool call to respond to\n * @param args - The parsed arguments for the tool\n * @returns ToolResultContent with the execution result or error\n */\nexport async function executeClientTool(\n tool: TamboTool,\n toolCallId: string,\n args: Record<string, unknown>,\n): Promise<ToolResultContent> {\n try {\n const result = await tool.tool(args);\n\n // Transform result to content if transformer provided\n let content: (TextContent | ResourceContent)[];\n if (tool.transformToContent) {\n // transformToContent may return content parts in beta format\n // Convert to content format (TextContent | ResourceContent)\n const transformed = await tool.transformToContent(result);\n content = transformed.map((part) => {\n if (part.type === \"text\" && \"text\" in part && part.text) {\n return { type: \"text\" as const, text: part.text };\n }\n // For other types, stringify as text\n return {\n type: \"text\" as const,\n text: JSON.stringify(part),\n };\n });\n } else {\n // Default: stringify result as text\n content = [\n {\n type: \"text\" as const,\n text: typeof result === \"string\" ? result : JSON.stringify(result),\n },\n ];\n }\n\n return {\n type: \"tool_result\",\n toolUseId: toolCallId,\n content,\n };\n } catch (error) {\n return {\n type: \"tool_result\",\n toolUseId: toolCallId,\n isError: true,\n content: [\n {\n type: \"text\" as const,\n text:\n error instanceof Error ? error.message : \"Tool execution failed\",\n },\n ],\n };\n }\n}\n\n/**\n * Execute all pending tool calls and return their results.\n * Tools are executed sequentially to avoid race conditions when\n * tools may have side effects that depend on each other.\n * @param toolCalls - Map of tool call IDs to their call details\n * @param registry - Registry of tool names to their definitions (Map or Record)\n * @returns Array of ToolResultContent for all executed tools\n */\nexport async function executeAllPendingTools(\n toolCalls: Map<string, PendingToolCall>,\n registry: Map<string, TamboTool> | Record<string, TamboTool>,\n): Promise<ToolResultContent[]> {\n const results: ToolResultContent[] = [];\n\n // Normalize registry to allow lookup regardless of Map or Record\n const getTool = (name: string): TamboTool | undefined => {\n if (registry instanceof Map) {\n return registry.get(name);\n }\n return registry[name];\n };\n\n for (const [toolCallId, { name, input }] of toolCalls) {\n const tool = getTool(name);\n if (!tool) {\n results.push({\n type: \"tool_result\",\n toolUseId: toolCallId,\n isError: true,\n content: [\n {\n type: \"text\" as const,\n text: `Tool \"${name}\" not found in registry`,\n },\n ],\n });\n continue;\n }\n\n const result = await executeClientTool(tool, toolCallId, input);\n results.push(result);\n }\n\n return results;\n}\n"]}
@@ -1,32 +0,0 @@
1
- /**
2
- * Unstrictify tool call parameters using the original JSON Schema.
3
- *
4
- * When OpenAI's structured outputs mode is enabled, all optional parameters
5
- * become required-and-nullable. The LLM then sends `null` for parameters the
6
- * user didn't specify. This module reverses that transformation by comparing
7
- * the LLM's output against the original schema and stripping nulls for
8
- * parameters that were originally optional and non-nullable.
9
- *
10
- * Copied from packages/core/src/strictness/tool-call-strict.ts (minus the
11
- * OpenAI-specific `unstrictifyToolCallRequest` wrapper).
12
- */
13
- import type { JSONSchema7, JSONSchema7Definition } from "json-schema";
14
- /**
15
- * Unstrictify tool call params using the original JSON Schema.
16
- *
17
- * Unlike the private `unstrictifyToolCallParams` which throws on unknown params,
18
- * this function separates params into schema-defined vs `_tambo_*` pass-through
19
- * (server-injected params not in the original schema), unstrictifies only the
20
- * schema-defined ones, and merges pass-through params back. Unknown keys that
21
- * aren't in the schema and don't have the `_tambo_` prefix are dropped.
22
- * @returns The params with strictification-induced nulls stripped for optional
23
- * non-nullable properties, and pass-through params preserved as-is.
24
- */
25
- export declare function unstrictifyToolCallParamsFromSchema(originalSchema: JSONSchema7, params: Record<string, unknown>): Record<string, unknown>;
26
- /**
27
- * Check if a JSON Schema definition allows null values.
28
- * @param originalSchema - The schema definition to check
29
- * @returns True if the schema allows null values
30
- */
31
- export declare function canBeNull(originalSchema: JSONSchema7Definition): boolean;
32
- //# sourceMappingURL=unstrictify.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unstrictify.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/unstrictify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAsItE;;;;;;;;;;GAUG;AACH,wBAAgB,mCAAmC,CACjD,cAAc,EAAE,WAAW,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBzB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,cAAc,EAAE,qBAAqB,GAAG,OAAO,CAaxE"}
@@ -1,159 +0,0 @@
1
- "use strict";
2
- /**
3
- * Unstrictify tool call parameters using the original JSON Schema.
4
- *
5
- * When OpenAI's structured outputs mode is enabled, all optional parameters
6
- * become required-and-nullable. The LLM then sends `null` for parameters the
7
- * user didn't specify. This module reverses that transformation by comparing
8
- * the LLM's output against the original schema and stripping nulls for
9
- * parameters that were originally optional and non-nullable.
10
- *
11
- * Copied from packages/core/src/strictness/tool-call-strict.ts (minus the
12
- * OpenAI-specific `unstrictifyToolCallRequest` wrapper).
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.unstrictifyToolCallParamsFromSchema = unstrictifyToolCallParamsFromSchema;
16
- exports.canBeNull = canBeNull;
17
- /**
18
- * Unstrictify the parameters of a tool call request.
19
- *
20
- * This effectively reverses the process of strictifyToolCallParams, for a
21
- * tool call request that was built from a strict JSON Schema, by returning a
22
- * updated tool call request with the parameter values unstrictified.
23
- */
24
- function unstrictifyToolCallParams(originalToolParamSchema, toolCallRequestParams) {
25
- if (originalToolParamSchema.type !== "object") {
26
- throw new Error(`tool call parameter schema must be an object, instead got ${originalToolParamSchema.type} / ${typeof originalToolParamSchema}`);
27
- }
28
- const newParams = Object.entries(toolCallRequestParams)
29
- .map(([parameterName, parameterValue]) => {
30
- const isRequired = originalToolParamSchema.required?.includes(parameterName);
31
- // find the param in the original tool schema
32
- const originalParamSchema = parameterName in (originalToolParamSchema.properties ?? {})
33
- ? originalToolParamSchema.properties?.[parameterName]
34
- : undefined;
35
- // This should never happen, because the strict schema was derived from
36
- // the original schema, so the parameter should always be present.
37
- if (!originalParamSchema) {
38
- throw new Error(`Tool call request parameter ${parameterName} not found in original tool`);
39
- }
40
- if (parameterValue === null &&
41
- !canBeNull(originalParamSchema) &&
42
- !isRequired) {
43
- // This is the meat of this function. In the strict schema, this is
44
- // "required and can be null", but in the original schema, the param was
45
- // not required.
46
- if (typeof originalParamSchema === "object" &&
47
- "default" in originalParamSchema) {
48
- return [parameterName, originalParamSchema.default];
49
- }
50
- return undefined;
51
- }
52
- // recurse into arrays
53
- if (typeof originalParamSchema === "object" &&
54
- originalParamSchema.type === "array") {
55
- const arrayValue = parameterValue;
56
- const itemSchema = originalParamSchema.items;
57
- if (Array.isArray(arrayValue) &&
58
- itemSchema &&
59
- typeof itemSchema === "object" &&
60
- !Array.isArray(itemSchema)) {
61
- const newArrayValue = arrayValue.map((item) => {
62
- if (itemSchema.type === "object" &&
63
- typeof item === "object" &&
64
- item !== null) {
65
- // recurse into each object in the array
66
- return unstrictifyToolCallParams(itemSchema, item);
67
- }
68
- return item;
69
- });
70
- return [parameterName, newArrayValue];
71
- }
72
- return [parameterName, parameterValue];
73
- }
74
- // recurse into the parameter value, passing along the matching original schema
75
- if (typeof originalParamSchema === "object" &&
76
- originalParamSchema.type === "object") {
77
- // If the LLM sent a JSON string instead of an object (common with z.any() schemas),
78
- // try to parse it
79
- let objectValue = parameterValue;
80
- if (typeof parameterValue === "string") {
81
- try {
82
- const parsed = JSON.parse(parameterValue);
83
- if (typeof parsed === "object" && parsed !== null) {
84
- objectValue = parsed;
85
- }
86
- }
87
- catch {
88
- // Not valid JSON, keep original value
89
- }
90
- }
91
- // Only recurse if we have an actual object AND the schema has properties defined.
92
- // If the schema has no properties (e.g., z.any() which produces {type: 'object', anyOf: [...]}),
93
- // just return the value as-is without recursing.
94
- const hasProperties = originalParamSchema.properties &&
95
- Object.keys(originalParamSchema.properties).length > 0;
96
- if (hasProperties &&
97
- typeof objectValue === "object" &&
98
- objectValue !== null &&
99
- !Array.isArray(objectValue)) {
100
- const newParamValue = unstrictifyToolCallParams(originalParamSchema, objectValue);
101
- return [parameterName, newParamValue];
102
- }
103
- // Return the (possibly parsed) object value without recursing
104
- return [parameterName, objectValue];
105
- }
106
- return [parameterName, parameterValue];
107
- })
108
- .filter((param) => param !== undefined);
109
- return Object.fromEntries(newParams);
110
- }
111
- /**
112
- * Unstrictify tool call params using the original JSON Schema.
113
- *
114
- * Unlike the private `unstrictifyToolCallParams` which throws on unknown params,
115
- * this function separates params into schema-defined vs `_tambo_*` pass-through
116
- * (server-injected params not in the original schema), unstrictifies only the
117
- * schema-defined ones, and merges pass-through params back. Unknown keys that
118
- * aren't in the schema and don't have the `_tambo_` prefix are dropped.
119
- * @returns The params with strictification-induced nulls stripped for optional
120
- * non-nullable properties, and pass-through params preserved as-is.
121
- */
122
- function unstrictifyToolCallParamsFromSchema(originalSchema, params) {
123
- if (originalSchema.type !== "object") {
124
- return params;
125
- }
126
- const schemaProperties = originalSchema.properties ?? {};
127
- const schemaDefinedParams = {};
128
- const passThroughParams = {};
129
- for (const [key, value] of Object.entries(params)) {
130
- if (key in schemaProperties) {
131
- schemaDefinedParams[key] = value;
132
- }
133
- else if (key.startsWith("_tambo_")) {
134
- passThroughParams[key] = value;
135
- }
136
- // Unknown keys not in schema and not _tambo_* are dropped —
137
- // they're likely hallucinated by the model.
138
- }
139
- const unstrictified = unstrictifyToolCallParams(originalSchema, schemaDefinedParams);
140
- return { ...unstrictified, ...passThroughParams };
141
- }
142
- /**
143
- * Check if a JSON Schema definition allows null values.
144
- * @param originalSchema - The schema definition to check
145
- * @returns True if the schema allows null values
146
- */
147
- function canBeNull(originalSchema) {
148
- if (typeof originalSchema !== "object") {
149
- return false;
150
- }
151
- if (originalSchema.type === "null") {
152
- return true;
153
- }
154
- if (originalSchema.anyOf?.some((anyOf) => canBeNull(anyOf))) {
155
- return true;
156
- }
157
- return false;
158
- }
159
- //# sourceMappingURL=unstrictify.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unstrictify.js","sourceRoot":"","sources":["../../../src/v1/utils/unstrictify.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAmJH,kFA4BC;AAOD,8BAaC;AA/LD;;;;;;GAMG;AACH,SAAS,yBAAyB,CAChC,uBAAoC,EACpC,qBAA8C;IAE9C,IAAI,uBAAuB,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,6DAA6D,uBAAuB,CAAC,IAAI,MAAM,OAAO,uBAAuB,EAAE,CAChI,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC;SACpD,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,EAAE;QACvC,MAAM,UAAU,GACd,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC5D,6CAA6C;QAC7C,MAAM,mBAAmB,GACvB,aAAa,IAAI,CAAC,uBAAuB,CAAC,UAAU,IAAI,EAAE,CAAC;YACzD,CAAC,CAAC,uBAAuB,CAAC,UAAU,EAAE,CAAC,aAAa,CAAC;YACrD,CAAC,CAAC,SAAS,CAAC;QAEhB,uEAAuE;QACvE,kEAAkE;QAClE,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,+BAA+B,aAAa,6BAA6B,CAC1E,CAAC;QACJ,CAAC;QAED,IACE,cAAc,KAAK,IAAI;YACvB,CAAC,SAAS,CAAC,mBAAmB,CAAC;YAC/B,CAAC,UAAU,EACX,CAAC;YACD,mEAAmE;YACnE,wEAAwE;YACxE,gBAAgB;YAChB,IACE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AM,iBAAiB,GAA4B,EAAE,CAAC;IAEtD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAC5B,mBAAmB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnC,CAAC;aAAM,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACrC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACjC,CAAC;QACD,4DAA4D;QAC5D,4CAA4C;IAC9C,CAAC;IAED,MAAM,aAAa,GAAG,yBAAyB,CAC7C,cAAc,EACd,mBAAmB,CACpB,CAAC;IAEF,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAC,cAAqC;IAC7D,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,cAAc,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Unstrictify tool call parameters using the original JSON Schema.\n *\n * When OpenAI's structured outputs mode is enabled, all optional parameters\n * become required-and-nullable. The LLM then sends `null` for parameters the\n * user didn't specify. This module reverses that transformation by comparing\n * the LLM's output against the original schema and stripping nulls for\n * parameters that were originally optional and non-nullable.\n *\n * Copied from packages/core/src/strictness/tool-call-strict.ts (minus the\n * OpenAI-specific `unstrictifyToolCallRequest` wrapper).\n */\n\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\n\n/**\n * Unstrictify the parameters of a tool call request.\n *\n * This effectively reverses the process of strictifyToolCallParams, for a\n * tool call request that was built from a strict JSON Schema, by returning a\n * updated tool call request with the parameter values unstrictified.\n */\nfunction unstrictifyToolCallParams(\n originalToolParamSchema: JSONSchema7,\n toolCallRequestParams: Record<string, unknown>,\n): Record<string, unknown> {\n if (originalToolParamSchema.type !== \"object\") {\n throw new Error(\n `tool call parameter schema must be an object, instead got ${originalToolParamSchema.type} / ${typeof originalToolParamSchema}`,\n );\n }\n const newParams = Object.entries(toolCallRequestParams)\n .map(([parameterName, parameterValue]) => {\n const isRequired =\n originalToolParamSchema.required?.includes(parameterName);\n // find the param in the original tool schema\n const originalParamSchema =\n parameterName in (originalToolParamSchema.properties ?? {})\n ? originalToolParamSchema.properties?.[parameterName]\n : undefined;\n\n // This should never happen, because the strict schema was derived from\n // the original schema, so the parameter should always be present.\n if (!originalParamSchema) {\n throw new Error(\n `Tool call request parameter ${parameterName} not found in original tool`,\n );\n }\n\n if (\n parameterValue === null &&\n !canBeNull(originalParamSchema) &&\n !isRequired\n ) {\n // This is the meat of this function. In the strict schema, this is\n // \"required and can be null\", but in the original schema, the param was\n // not required.\n if (\n typeof originalParamSchema === \"object\" &&\n \"default\" in originalParamSchema\n ) {\n return [parameterName, originalParamSchema.default] as const;\n }\n return undefined;\n }\n\n // recurse into arrays\n if (\n typeof originalParamSchema === \"object\" &&\n originalParamSchema.type === \"array\"\n ) {\n const arrayValue = parameterValue as unknown[];\n const itemSchema = originalParamSchema.items;\n if (\n Array.isArray(arrayValue) &&\n itemSchema &&\n typeof itemSchema === \"object\" &&\n !Array.isArray(itemSchema)\n ) {\n const newArrayValue = arrayValue.map((item) => {\n if (\n itemSchema.type === \"object\" &&\n typeof item === \"object\" &&\n item !== null\n ) {\n // recurse into each object in the array\n return unstrictifyToolCallParams(\n itemSchema,\n item as Record<string, unknown>,\n );\n }\n return item;\n });\n return [parameterName, newArrayValue] as const;\n }\n return [parameterName, parameterValue] as const;\n }\n\n // recurse into the parameter value, passing along the matching original schema\n if (\n typeof originalParamSchema === \"object\" &&\n originalParamSchema.type === \"object\"\n ) {\n // If the LLM sent a JSON string instead of an object (common with z.any() schemas),\n // try to parse it\n let objectValue = parameterValue;\n if (typeof parameterValue === \"string\") {\n try {\n const parsed = JSON.parse(parameterValue);\n if (typeof parsed === \"object\" && parsed !== null) {\n objectValue = parsed;\n }\n } catch {\n // Not valid JSON, keep original value\n }\n }\n\n // Only recurse if we have an actual object AND the schema has properties defined.\n // If the schema has no properties (e.g., z.any() which produces {type: 'object', anyOf: [...]}),\n // just return the value as-is without recursing.\n const hasProperties =\n originalParamSchema.properties &&\n Object.keys(originalParamSchema.properties).length > 0;\n\n if (\n hasProperties &&\n typeof objectValue === \"object\" &&\n objectValue !== null &&\n !Array.isArray(objectValue)\n ) {\n const newParamValue = unstrictifyToolCallParams(\n originalParamSchema,\n objectValue as Record<string, unknown>,\n );\n return [parameterName, newParamValue] as const;\n }\n\n // Return the (possibly parsed) object value without recursing\n return [parameterName, objectValue] as const;\n }\n\n return [parameterName, parameterValue] as const;\n })\n .filter((param) => param !== undefined);\n return Object.fromEntries(newParams);\n}\n\n/**\n * Unstrictify tool call params using the original JSON Schema.\n *\n * Unlike the private `unstrictifyToolCallParams` which throws on unknown params,\n * this function separates params into schema-defined vs `_tambo_*` pass-through\n * (server-injected params not in the original schema), unstrictifies only the\n * schema-defined ones, and merges pass-through params back. Unknown keys that\n * aren't in the schema and don't have the `_tambo_` prefix are dropped.\n * @returns The params with strictification-induced nulls stripped for optional\n * non-nullable properties, and pass-through params preserved as-is.\n */\nexport function unstrictifyToolCallParamsFromSchema(\n originalSchema: JSONSchema7,\n params: Record<string, unknown>,\n): Record<string, unknown> {\n if (originalSchema.type !== \"object\") {\n return params;\n }\n\n const schemaProperties = originalSchema.properties ?? {};\n const schemaDefinedParams: Record<string, unknown> = {};\n const passThroughParams: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (key in schemaProperties) {\n schemaDefinedParams[key] = value;\n } else if (key.startsWith(\"_tambo_\")) {\n passThroughParams[key] = value;\n }\n // Unknown keys not in schema and not _tambo_* are dropped —\n // they're likely hallucinated by the model.\n }\n\n const unstrictified = unstrictifyToolCallParams(\n originalSchema,\n schemaDefinedParams,\n );\n\n return { ...unstrictified, ...passThroughParams };\n}\n\n/**\n * Check if a JSON Schema definition allows null values.\n * @param originalSchema - The schema definition to check\n * @returns True if the schema allows null values\n */\nexport function canBeNull(originalSchema: JSONSchema7Definition): boolean {\n if (typeof originalSchema !== \"object\") {\n return false;\n }\n\n if (originalSchema.type === \"null\") {\n return true;\n }\n\n if (originalSchema.anyOf?.some((anyOf) => canBeNull(anyOf))) {\n return true;\n }\n return false;\n}\n"]}
@@ -1,185 +0,0 @@
1
- import { type OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
2
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
- import { ClientNotification, ClientRequest, CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
5
- import { JSONSchema7 } from "json-schema";
6
- import { MCPTransport } from "../model/mcp-server-info.js";
7
- export { MCPTransport };
8
- /**
9
- * Handler for MCP elicitation requests.
10
- * Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
11
- * @param request - The elicitation request from the server
12
- * @param extra - Additional context including AbortSignal for cancellation
13
- * @returns Promise resolving to the elicitation result
14
- * @example
15
- * ```typescript
16
- * const handler: MCPElicitationHandler = async (request, extra) => {
17
- * // Listen for cancellation
18
- * extra.signal.addEventListener('abort', () => {
19
- * console.log('Request cancelled');
20
- * });
21
- *
22
- * // Return user's response
23
- * return {
24
- * action: 'accept',
25
- * content: { name: 'John' }
26
- * };
27
- * };
28
- * ```
29
- */
30
- export type MCPElicitationHandler = (e: ElicitRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<ElicitResult>;
31
- /**
32
- * Handler for MCP sampling requests (create_message).
33
- * Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
34
- * @param request - The sampling/create_message request from the server
35
- * @param extra - Additional context including AbortSignal for cancellation
36
- * @returns Promise resolving to the sampling result
37
- */
38
- export type MCPSamplingHandler = (e: CreateMessageRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<CreateMessageResult>;
39
- /**
40
- * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities
41
- * @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)
42
- * @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)
43
- * @example
44
- * ```typescript
45
- * const mcp = await MCPClient.create(
46
- * 'https://api.example.com/mcp',
47
- * MCPTransport.HTTP,
48
- * {},
49
- * undefined,
50
- * undefined,
51
- * {
52
- * elicitation: (e, extra) => Promise.resolve({...}),
53
- * },
54
- * );
55
- * ```
56
- */
57
- export interface MCPHandlers {
58
- elicitation: MCPElicitationHandler;
59
- sampling: MCPSamplingHandler;
60
- }
61
- /**
62
- * A client for interacting with MCP (Model Context Protocol) servers.
63
- * Provides a simple interface for listing and calling tools exposed by the server.
64
- * @example
65
- * ```typescript
66
- * const mcp = await MCPClient.create('https://api.example.com/mcp');
67
- * const tools = await mcp.listTools();
68
- * const result = await mcp.callTool('toolName', { arg1: 'value1' });
69
- * ```
70
- */
71
- export declare class MCPClient {
72
- /**
73
- * The underlying MCP client
74
- *
75
- * Be careful not to mutate the client directly, use the methods provided instead.
76
- */
77
- client: Client;
78
- private transport;
79
- private transportType;
80
- sessionId?: string;
81
- private endpoint;
82
- private headers;
83
- private authProvider?;
84
- private handlers;
85
- /**
86
- * Private constructor to enforce using the static create method.
87
- * @param endpoint - The URL of the MCP server to connect to
88
- * @param transportType - The transport to use for the MCP client
89
- * @param headers - Optional custom headers to include in requests
90
- */
91
- private constructor();
92
- /**
93
- * Creates and initializes a new MCPClient instance. This is the recommended
94
- * way to create an MCPClient as it handles both instantiation and connection
95
- * setup.
96
- * @param endpoint - The URL of the MCP server to connect to
97
- * @param transportType - The transport type to use for the MCP client. Defaults to HTTP.
98
- * @param headers - Optional custom headers to include in requests
99
- * @param authProvider - Optional auth provider to use for authentication
100
- * @param sessionId - Optional session id to use for the MCP client - if not
101
- * provided, a new session will be created
102
- * @returns A connected MCPClient instance ready for use
103
- * @throws {Error} Will throw an error if connection fails
104
- */
105
- static create(endpoint: string, transportType: MCPTransport | undefined, headers: Record<string, string> | undefined, authProvider: OAuthClientProvider | undefined, sessionId: string | undefined, handlers?: Partial<MCPHandlers>): Promise<MCPClient>;
106
- private initializeTransport;
107
- /**
108
- * Initializes the MCP client with the appropriate capabilities and handlers
109
- * @returns The initialized MCP client
110
- */
111
- private initializeClient;
112
- /**
113
- * Retrieves a complete list of all available tools from the MCP server.
114
- * Handles pagination automatically by following cursors until all tools are fetched.
115
- * @returns A complete list of all available tools and their descriptions
116
- * @throws {Error} Will throw an error if any server request fails during pagination
117
- */
118
- listTools(): Promise<MCPToolSpec[]>;
119
- getServerCapabilities(): {
120
- experimental?: {
121
- [x: string]: object;
122
- } | undefined;
123
- logging?: object | undefined;
124
- completions?: object | undefined;
125
- prompts?: {
126
- listChanged?: boolean | undefined;
127
- } | undefined;
128
- resources?: {
129
- subscribe?: boolean | undefined;
130
- listChanged?: boolean | undefined;
131
- } | undefined;
132
- tools?: {
133
- listChanged?: boolean | undefined;
134
- } | undefined;
135
- tasks?: {
136
- [x: string]: unknown;
137
- list?: object | undefined;
138
- cancel?: object | undefined;
139
- requests?: {
140
- [x: string]: unknown;
141
- tools?: {
142
- [x: string]: unknown;
143
- call?: object | undefined;
144
- } | undefined;
145
- } | undefined;
146
- } | undefined;
147
- } | undefined;
148
- getServerVersion(): {
149
- version: string;
150
- name: string;
151
- websiteUrl?: string | undefined;
152
- description?: string | undefined;
153
- icons?: {
154
- src: string;
155
- mimeType?: string | undefined;
156
- sizes?: string[] | undefined;
157
- theme?: "light" | "dark" | undefined;
158
- }[] | undefined;
159
- title?: string | undefined;
160
- } | undefined;
161
- getInstructions(): string | undefined;
162
- /**
163
- * Calls a specific tool on the MCP server with the provided arguments.
164
- * @param name - The name of the tool to call
165
- * @param args - Arguments to pass to the tool, must match the tool's expected schema
166
- * @returns The result from the tool execution
167
- * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid
168
- */
169
- callTool(name: string, args: Record<string, unknown>, _meta?: Record<string, unknown>): Promise<MCPToolCallResult>;
170
- updateElicitationHandler(handler: MCPElicitationHandler | undefined): void;
171
- updateSamplingHandler(handler: MCPSamplingHandler | undefined): void;
172
- close(): Promise<void>;
173
- }
174
- /**
175
- * The result of a tool call.
176
- * This is the same as the result of a tool call in the OpenAI SDK, but is reified here
177
- */
178
- export type MCPToolCallResult = Awaited<ReturnType<typeof Client.prototype.callTool>>;
179
- export interface MCPToolSpec {
180
- name: string;
181
- description?: string;
182
- inputSchema?: JSONSchema7;
183
- maxCalls?: number;
184
- }
185
- //# sourceMappingURL=mcp-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EAEpB,mBAAmB,EACnB,aAAa,EAEb,YAAY,EACb,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAE,YA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