@tambo-ai/react 0.18.2 → 0.19.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 (181) hide show
  1. package/dist/hooks/index.d.ts +1 -1
  2. package/dist/hooks/index.d.ts.map +1 -1
  3. package/dist/hooks/index.js +2 -2
  4. package/dist/hooks/index.js.map +1 -1
  5. package/dist/hooks/react-query-hooks.d.ts +8 -0
  6. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  7. package/dist/hooks/react-query-hooks.js +8 -0
  8. package/dist/hooks/react-query-hooks.js.map +1 -1
  9. package/dist/hooks/use-component-state.d.ts +0 -3
  10. package/dist/hooks/use-component-state.d.ts.map +1 -1
  11. package/dist/hooks/use-component-state.js +8 -26
  12. package/dist/hooks/use-component-state.js.map +1 -1
  13. package/dist/hooks/use-current-message.d.ts +27 -7
  14. package/dist/hooks/use-current-message.d.ts.map +1 -1
  15. package/dist/hooks/use-current-message.js +27 -7
  16. package/dist/hooks/use-current-message.js.map +1 -1
  17. package/dist/hooks/use-streaming-props.d.ts +0 -2
  18. package/dist/hooks/use-streaming-props.d.ts.map +1 -1
  19. package/dist/hooks/use-streaming-props.js +0 -2
  20. package/dist/hooks/use-streaming-props.js.map +1 -1
  21. package/dist/hooks/use-suggestions.d.ts +0 -1
  22. package/dist/hooks/use-suggestions.d.ts.map +1 -1
  23. package/dist/hooks/use-suggestions.js +0 -1
  24. package/dist/hooks/use-suggestions.js.map +1 -1
  25. package/dist/hooks/use-tambo-threads.d.ts +35 -5
  26. package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
  27. package/dist/hooks/use-tambo-threads.js +11 -3
  28. package/dist/hooks/use-tambo-threads.js.map +1 -1
  29. package/dist/hooks/use-thread-input.d.ts +0 -1
  30. package/dist/hooks/use-thread-input.d.ts.map +1 -1
  31. package/dist/hooks/use-thread-input.js +0 -1
  32. package/dist/hooks/use-thread-input.js.map +1 -1
  33. package/dist/index.d.ts +2 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +10 -3
  36. package/dist/index.js.map +1 -1
  37. package/dist/model/component-metadata.d.ts +6 -3
  38. package/dist/model/component-metadata.d.ts.map +1 -1
  39. package/dist/model/component-metadata.js.map +1 -1
  40. package/dist/model/generate-component-response.d.ts +9 -2
  41. package/dist/model/generate-component-response.d.ts.map +1 -1
  42. package/dist/model/generate-component-response.js +5 -0
  43. package/dist/model/generate-component-response.js.map +1 -1
  44. package/dist/model/tambo-thread.d.ts +4 -2
  45. package/dist/model/tambo-thread.d.ts.map +1 -1
  46. package/dist/model/tambo-thread.js.map +1 -1
  47. package/dist/model/validate-input.d.ts +5 -0
  48. package/dist/model/validate-input.d.ts.map +1 -1
  49. package/dist/model/validate-input.js +5 -1
  50. package/dist/model/validate-input.js.map +1 -1
  51. package/dist/providers/tambo-client-provider.d.ts +31 -0
  52. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-client-provider.js +21 -0
  54. package/dist/providers/tambo-client-provider.js.map +1 -1
  55. package/dist/providers/tambo-component-provider.d.ts +12 -0
  56. package/dist/providers/tambo-component-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-component-provider.js +24 -0
  58. package/dist/providers/tambo-component-provider.js.map +1 -1
  59. package/dist/providers/tambo-provider.d.ts +18 -1
  60. package/dist/providers/tambo-provider.d.ts.map +1 -1
  61. package/dist/providers/tambo-provider.js +25 -2
  62. package/dist/providers/tambo-provider.js.map +1 -1
  63. package/dist/providers/tambo-registry-provider.d.ts +14 -1
  64. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  65. package/dist/providers/tambo-registry-provider.js +25 -0
  66. package/dist/providers/tambo-registry-provider.js.map +1 -1
  67. package/dist/providers/tambo-thread-provider.d.ts +26 -2
  68. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  69. package/dist/providers/tambo-thread-provider.js +46 -26
  70. package/dist/providers/tambo-thread-provider.js.map +1 -1
  71. package/dist/util/generate-component.d.ts +5 -1
  72. package/dist/util/generate-component.d.ts.map +1 -1
  73. package/dist/util/generate-component.js +5 -1
  74. package/dist/util/generate-component.js.map +1 -1
  75. package/dist/util/query-utils.d.ts +16 -0
  76. package/dist/util/query-utils.d.ts.map +1 -1
  77. package/dist/util/query-utils.js +16 -0
  78. package/dist/util/query-utils.js.map +1 -1
  79. package/dist/util/registry.d.ts +27 -1
  80. package/dist/util/registry.d.ts.map +1 -1
  81. package/dist/util/registry.js +29 -4
  82. package/dist/util/registry.js.map +1 -1
  83. package/dist/util/tool-caller.d.ts +6 -0
  84. package/dist/util/tool-caller.d.ts.map +1 -1
  85. package/dist/util/tool-caller.js +6 -0
  86. package/dist/util/tool-caller.js.map +1 -1
  87. package/esm/hooks/index.d.ts +1 -1
  88. package/esm/hooks/index.d.ts.map +1 -1
  89. package/esm/hooks/index.js +1 -1
  90. package/esm/hooks/index.js.map +1 -1
  91. package/esm/hooks/react-query-hooks.d.ts +8 -0
  92. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  93. package/esm/hooks/react-query-hooks.js +8 -0
  94. package/esm/hooks/react-query-hooks.js.map +1 -1
  95. package/esm/hooks/use-component-state.d.ts +0 -3
  96. package/esm/hooks/use-component-state.d.ts.map +1 -1
  97. package/esm/hooks/use-component-state.js +2 -23
  98. package/esm/hooks/use-component-state.js.map +1 -1
  99. package/esm/hooks/use-current-message.d.ts +27 -7
  100. package/esm/hooks/use-current-message.d.ts.map +1 -1
  101. package/esm/hooks/use-current-message.js +27 -7
  102. package/esm/hooks/use-current-message.js.map +1 -1
  103. package/esm/hooks/use-streaming-props.d.ts +0 -2
  104. package/esm/hooks/use-streaming-props.d.ts.map +1 -1
  105. package/esm/hooks/use-streaming-props.js +0 -2
  106. package/esm/hooks/use-streaming-props.js.map +1 -1
  107. package/esm/hooks/use-suggestions.d.ts +0 -1
  108. package/esm/hooks/use-suggestions.d.ts.map +1 -1
  109. package/esm/hooks/use-suggestions.js +0 -1
  110. package/esm/hooks/use-suggestions.js.map +1 -1
  111. package/esm/hooks/use-tambo-threads.d.ts +35 -5
  112. package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
  113. package/esm/hooks/use-tambo-threads.js +10 -2
  114. package/esm/hooks/use-tambo-threads.js.map +1 -1
  115. package/esm/hooks/use-thread-input.d.ts +0 -1
  116. package/esm/hooks/use-thread-input.d.ts.map +1 -1
  117. package/esm/hooks/use-thread-input.js +0 -1
  118. package/esm/hooks/use-thread-input.js.map +1 -1
  119. package/esm/index.d.ts +2 -2
  120. package/esm/index.d.ts.map +1 -1
  121. package/esm/index.js +2 -2
  122. package/esm/index.js.map +1 -1
  123. package/esm/model/component-metadata.d.ts +6 -3
  124. package/esm/model/component-metadata.d.ts.map +1 -1
  125. package/esm/model/component-metadata.js.map +1 -1
  126. package/esm/model/generate-component-response.d.ts +9 -2
  127. package/esm/model/generate-component-response.d.ts.map +1 -1
  128. package/esm/model/generate-component-response.js +5 -0
  129. package/esm/model/generate-component-response.js.map +1 -1
  130. package/esm/model/tambo-thread.d.ts +4 -2
  131. package/esm/model/tambo-thread.d.ts.map +1 -1
  132. package/esm/model/tambo-thread.js.map +1 -1
  133. package/esm/model/validate-input.d.ts +5 -0
  134. package/esm/model/validate-input.d.ts.map +1 -1
  135. package/esm/model/validate-input.js +5 -1
  136. package/esm/model/validate-input.js.map +1 -1
  137. package/esm/providers/tambo-client-provider.d.ts +31 -0
  138. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  139. package/esm/providers/tambo-client-provider.js +21 -0
  140. package/esm/providers/tambo-client-provider.js.map +1 -1
  141. package/esm/providers/tambo-component-provider.d.ts +12 -0
  142. package/esm/providers/tambo-component-provider.d.ts.map +1 -1
  143. package/esm/providers/tambo-component-provider.js +24 -0
  144. package/esm/providers/tambo-component-provider.js.map +1 -1
  145. package/esm/providers/tambo-provider.d.ts +18 -1
  146. package/esm/providers/tambo-provider.d.ts.map +1 -1
  147. package/esm/providers/tambo-provider.js +25 -2
  148. package/esm/providers/tambo-provider.js.map +1 -1
  149. package/esm/providers/tambo-registry-provider.d.ts +14 -1
  150. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  151. package/esm/providers/tambo-registry-provider.js +25 -0
  152. package/esm/providers/tambo-registry-provider.js.map +1 -1
  153. package/esm/providers/tambo-thread-provider.d.ts +26 -2
  154. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  155. package/esm/providers/tambo-thread-provider.js +46 -26
  156. package/esm/providers/tambo-thread-provider.js.map +1 -1
  157. package/esm/util/generate-component.d.ts +5 -1
  158. package/esm/util/generate-component.d.ts.map +1 -1
  159. package/esm/util/generate-component.js +5 -1
  160. package/esm/util/generate-component.js.map +1 -1
  161. package/esm/util/query-utils.d.ts +16 -0
  162. package/esm/util/query-utils.d.ts.map +1 -1
  163. package/esm/util/query-utils.js +16 -0
  164. package/esm/util/query-utils.js.map +1 -1
  165. package/esm/util/registry.d.ts +27 -1
  166. package/esm/util/registry.d.ts.map +1 -1
  167. package/esm/util/registry.js +28 -2
  168. package/esm/util/registry.js.map +1 -1
  169. package/esm/util/tool-caller.d.ts +6 -0
  170. package/esm/util/tool-caller.d.ts.map +1 -1
  171. package/esm/util/tool-caller.js +6 -0
  172. package/esm/util/tool-caller.js.map +1 -1
  173. package/package.json +4 -2
  174. package/dist/util/messages.d.ts +0 -3
  175. package/dist/util/messages.d.ts.map +0 -1
  176. package/dist/util/messages.js +0 -12
  177. package/dist/util/messages.js.map +0 -1
  178. package/esm/util/messages.d.ts +0 -3
  179. package/esm/util/messages.d.ts.map +0 -1
  180. package/esm/util/messages.js +0 -9
  181. package/esm/util/messages.js.map +0 -1
@@ -1,20 +1,36 @@
1
1
  import React, { createContext, useContext } from "react";
2
2
  import { useTamboThread } from "../providers";
3
3
  const TamboMessageContext = createContext({});
4
- /** Wraps all components, so that they can find what thread and message they are in */
4
+ /**
5
+ * Wraps all components, so that they can find what thread and message they are in
6
+ * @param props - props for the TamboMessageProvider
7
+ * @param props.children - The children to wrap
8
+ * @param props.threadId - The threadId of the thread
9
+ * @param props.messageId - The messageId of the message
10
+ * @returns The wrapped component
11
+ */
5
12
  export const TamboMessageProvider = ({ children, threadId, messageId }) => {
6
13
  // Use a unique key={...} to force a re-render when the messageId changes - this
7
14
  // make sure that if the rendered component is swapped into a tree (like if
8
15
  // you always show the last rendered component) then the state/etc is correct
9
16
  return (React.createElement(TamboMessageContext.Provider, { value: { threadId, messageId }, key: `${threadId}-${messageId}` }, children));
10
17
  };
11
- /** Wraps a component with a ComponentMessageProvider - this allows the provider
12
- * to be used outside of a TSX file */
18
+ /**
19
+ * Wraps a component with a ComponentMessageProvider - this allows the provider
20
+ * to be used outside of a TSX file
21
+ * @param children - The children to wrap
22
+ * @param threadId - The threadId of the thread
23
+ * @param messageId - The messageId of the message
24
+ * @returns The wrapped component
25
+ */
13
26
  export function wrapWithTamboMessageProvider(children, threadId, messageId) {
14
27
  return (React.createElement(TamboMessageProvider, { threadId: threadId, messageId: messageId }, children));
15
28
  }
16
- /** Hook used inside a component wrapped with ComponentMessageProvider, to get
17
- * the threadId and messageId */
29
+ /**
30
+ * Hook used inside a component wrapped with ComponentMessageProvider, to get
31
+ * the threadId and messageId
32
+ * @returns The threadId and messageId
33
+ */
18
34
  export const useTamboMessageContext = () => {
19
35
  const context = useContext(TamboMessageContext);
20
36
  if (!context) {
@@ -22,8 +38,12 @@ export const useTamboMessageContext = () => {
22
38
  }
23
39
  return context;
24
40
  };
25
- /** Hook used inside a component wrapped with ComponentMessageProvider, to get
26
- * the current message */
41
+ /**
42
+ * Hook used inside a component wrapped with ComponentMessageProvider, to get
43
+ * the current message. The current thread will be fetched from the server, if
44
+ * it is not already in the cache.
45
+ * @returns The current message that is used to render the component
46
+ */
27
47
  export const useTamboCurrentMessage = () => {
28
48
  const { messageId, threadId } = useTamboMessageContext();
29
49
  const { thread } = useTamboThread();
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"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EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\nconst TamboMessageContext = createContext<{\n threadId: string;\n messageId: string;\n}>({} as { threadId: string; messageId: string });\n\n/** Wraps all components, so that they can find what thread and message they are in */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<{ threadId: string; messageId: string }>\n> = ({ children, threadId, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider\n value={{ threadId, messageId }}\n key={`${threadId}-${messageId}`}\n >\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/** Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/** Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId */\n\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/** Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
1
+ {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,mBAAmB,GAAG,aAAa,CAGtC,EAA6C,CAAC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACxC,gFAAgF;IAChF,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,oBAAC,mBAAmB,CAAC,QAAQ,IAC3B,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAC9B,GAAG,EAAE,GAAG,QAAQ,IAAI,SAAS,EAAE,IAE9B,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAyB,EACzB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,CACL,oBAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,IAC3D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\nconst TamboMessageContext = createContext<{\n threadId: string;\n messageId: string;\n}>({} as { threadId: string; messageId: string });\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.threadId - The threadId of the thread\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<{ threadId: string; messageId: string }>\n> = ({ children, threadId, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider\n value={{ threadId, messageId }}\n key={`${threadId}-${messageId}`}\n >\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
@@ -3,11 +3,9 @@
3
3
  *
4
4
  * This hook streamlines the common pattern of updating component state when receiving new
5
5
  * streamed values from Tambo, eliminating the need to write repetitive useEffect code.
6
- *
7
6
  * @param currentState - The current state object from useTamboComponentState
8
7
  * @param setState - The setState function from useTamboComponentState
9
8
  * @param streamingProps - An object mapping state keys to prop values that should update the state
10
- *
11
9
  * @example
12
10
  * ```tsx
13
11
  * // Instead of writing a complex useEffect:
@@ -1 +1 @@
1
- {"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClE,YAAY,EAAE,CAAC,GAAG,SAAS,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,QAuB3B"}
1
+ {"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClE,YAAY,EAAE,CAAC,GAAG,SAAS,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,QAuB3B"}
@@ -4,11 +4,9 @@ import { useEffect } from "react";
4
4
  *
5
5
  * This hook streamlines the common pattern of updating component state when receiving new
6
6
  * streamed values from Tambo, eliminating the need to write repetitive useEffect code.
7
- *
8
7
  * @param currentState - The current state object from useTamboComponentState
9
8
  * @param setState - The setState function from useTamboComponentState
10
9
  * @param streamingProps - An object mapping state keys to prop values that should update the state
11
- *
12
10
  * @example
13
11
  * ```tsx
14
12
  * // Instead of writing a complex useEffect:
@@ -1 +1 @@
1
- {"version":3,"file":"use-streaming-props.js","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAA2B,EAC3B,QAA4B,EAC5B,cAA0B;IAE1B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,YAAY,GAAG,KAAK,CAAC;YACzB,MAAM,OAAO,GAAe,EAAE,CAAC;YAE/B,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACtD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvD,YAAY,GAAG,IAAI,CAAC;oBACpB,OAAO,CAAC,GAAc,CAAC,GAAG,KAAmB,CAAC;gBAChD,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,EAAE,CAAC;gBACjB,QAAQ,CAAC;oBACP,GAAG,YAAY;oBACf,GAAG,OAAO;iBACX,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,uDAAuD;IACzD,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { useEffect } from \"react\";\n\n/**\n * A helper hook that automatically updates Tambo component state when specified props change.\n *\n * This hook streamlines the common pattern of updating component state when receiving new\n * streamed values from Tambo, eliminating the need to write repetitive useEffect code.\n *\n * @param currentState - The current state object from useTamboComponentState\n * @param setState - The setState function from useTamboComponentState\n * @param streamingProps - An object mapping state keys to prop values that should update the state\n *\n * @example\n * ```tsx\n * // Instead of writing a complex useEffect:\n * const [emailState, setEmailState] = useTamboComponentState(\"email\", initialState);\n *\n * // Simply use:\n * useTamboStreamingProps(emailState, setEmailState, {\n * subject: aiGeneratedSubject,\n * body: aiGeneratedBody,\n * usersEmail: usersEmail\n * });\n * ```\n */\nexport function useTamboStreamingProps<T extends Record<string, any>>(\n currentState: T | undefined,\n setState: (state: T) => void,\n streamingProps: Partial<T>,\n) {\n useEffect(() => {\n if (currentState) {\n let shouldUpdate = false;\n const updates: Partial<T> = {};\n\n Object.entries(streamingProps).forEach(([key, value]) => {\n if (value !== undefined && value !== currentState[key]) {\n shouldUpdate = true;\n updates[key as keyof T] = value as T[keyof T];\n }\n });\n\n if (shouldUpdate) {\n setState({\n ...currentState,\n ...updates,\n });\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, setState, ...Object.values(streamingProps)]);\n}\n"]}
1
+ {"version":3,"file":"use-streaming-props.js","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAA2B,EAC3B,QAA4B,EAC5B,cAA0B;IAE1B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,YAAY,GAAG,KAAK,CAAC;YACzB,MAAM,OAAO,GAAe,EAAE,CAAC;YAE/B,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACtD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvD,YAAY,GAAG,IAAI,CAAC;oBACpB,OAAO,CAAC,GAAc,CAAC,GAAG,KAAmB,CAAC;gBAChD,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,EAAE,CAAC;gBACjB,QAAQ,CAAC;oBACP,GAAG,YAAY;oBACf,GAAG,OAAO;iBACX,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,uDAAuD;IACzD,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { useEffect } from \"react\";\n\n/**\n * A helper hook that automatically updates Tambo component state when specified props change.\n *\n * This hook streamlines the common pattern of updating component state when receiving new\n * streamed values from Tambo, eliminating the need to write repetitive useEffect code.\n * @param currentState - The current state object from useTamboComponentState\n * @param setState - The setState function from useTamboComponentState\n * @param streamingProps - An object mapping state keys to prop values that should update the state\n * @example\n * ```tsx\n * // Instead of writing a complex useEffect:\n * const [emailState, setEmailState] = useTamboComponentState(\"email\", initialState);\n *\n * // Simply use:\n * useTamboStreamingProps(emailState, setEmailState, {\n * subject: aiGeneratedSubject,\n * body: aiGeneratedBody,\n * usersEmail: usersEmail\n * });\n * ```\n */\nexport function useTamboStreamingProps<T extends Record<string, any>>(\n currentState: T | undefined,\n setState: (state: T) => void,\n streamingProps: Partial<T>,\n) {\n useEffect(() => {\n if (currentState) {\n let shouldUpdate = false;\n const updates: Partial<T> = {};\n\n Object.entries(streamingProps).forEach(([key, value]) => {\n if (value !== undefined && value !== currentState[key]) {\n shouldUpdate = true;\n updates[key as keyof T] = value as T[keyof T];\n }\n });\n\n if (shouldUpdate) {\n setState({\n ...currentState,\n ...updates,\n });\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, setState, ...Object.values(streamingProps)]);\n}\n"]}
@@ -38,7 +38,6 @@ export interface useTamboSuggestionsResultInternal {
38
38
  type useTamboSuggestionsResult = CombinedMutationResult<any, Error> & useTamboSuggestionsResultInternal;
39
39
  /**
40
40
  * Hook for managing Tambo AI suggestions in a thread
41
- *
42
41
  * @param options - Configuration options for suggestion generation
43
42
  * @returns Object containing suggestions state and control functions
44
43
  */
@@ -1 +1 @@
1
- {"version":3,"file":"use-suggestions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAO/C,OAAO,EACL,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EAGpB,MAAM,qBAAqB,CAAC;AAG7B;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,4EAA4E;IAC5E,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAC/C,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,MAAM,EAAE,CAAC,aAAa,E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,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAC/C,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,MAAM,EAAE,CAAC,aAAa,EAAE;QACtB,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpB,0DAA0D;IAC1D,YAAY,EAAE,sBAAsB,CAClC,IAAI,EACJ,KAAK,EACL;QAAE,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,CACxE,CAAC;IAEF,0DAA0D;IAC1D,cAAc,EAAE,sBAAsB,CACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,0BAA0B,GAAG,SAAS,EACvE,KAAK,EACL,eAAe,CAChB,CAAC;IAEF,yDAAyD;IACzD,iBAAiB,EAAE,mBAAmB,CACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,0BAA0B,GAAG,SAAS,EACvE,KAAK,CACN,CAAC;CACH;AAED,KAAK,yBAAyB,GAAG,sBAAsB,CAAC,GAAG,EAAE,KAAK,CAAC,GACjE,iCAAiC,CAAC;AAEpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,yBAAyB,CAmI3B"}
@@ -10,7 +10,6 @@ import { useTamboMutationResult, useTamboQuery, } from "./react-query-hooks";
10
10
  import { INPUT_ERROR_MESSAGES, useTamboThreadInput } from "./use-thread-input";
11
11
  /**
12
12
  * Hook for managing Tambo AI suggestions in a thread
13
- *
14
13
  * @param options - Configuration options for suggestion generation
15
14
  * @returns Object containing suggestions state and control functions
16
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"use-suggest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CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;QACL,WAAW;QACX,MAAM,EAAE,mBAAmB,CAAC,WAAW;QACvC,oBAAoB;QACpB,YAAY,EAAE,mBAAmB;QACjC,cAAc,EAAE,qBAAqB;QACrC,iBAAiB;QACjB,GAAG,sBAAsB,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { useEffect, useState } from \"react\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTambo } from \"../providers/tambo-provider\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport {\n CombinedMutationResult,\n combineMutationResults,\n} from \"../util/query-utils\";\nimport { getAvailableComponents } from \"../util/registry\";\nimport {\n UseTamboMutationResult,\n UseTamboQueryResult,\n useTamboMutationResult,\n useTamboQuery,\n} from \"./react-query-hooks\";\nimport { INPUT_ERROR_MESSAGES, useTamboThreadInput } from \"./use-thread-input\";\n\n/**\n * Configuration options for the useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsOptions {\n /** Maximum number of suggestions to generate (1-10, default 3) */\n maxSuggestions?: number;\n}\n\n/**\n * Return value interface for useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsResultInternal {\n /** List of available suggestions (also available in generateResult.data) */\n suggestions: TamboAI.Beta.Threads.Suggestion[];\n /** ID of the currently selected suggestion */\n selectedSuggestionId: string | null;\n /**\n * Accept and apply a suggestion (also available in acceptResult.mutateAsync)\n * @param suggestion - The suggestion to accept\n * @param shouldSubmit - Whether to automatically submit after accepting (default: false)\n */\n accept: (acceptOptions: {\n suggestion: TamboAI.Beta.Threads.Suggestion;\n shouldSubmit?: boolean;\n }) => Promise<void>;\n\n /** Result and network state for accepting a suggestion */\n acceptResult: UseTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >;\n\n /** Result and network state for generating suggestions */\n generateResult: UseTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >;\n\n /** The full suggestions query object from React Query */\n suggestionsResult: UseTamboQueryResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error\n >;\n}\n\ntype useTamboSuggestionsResult = CombinedMutationResult<any, Error> &\n useTamboSuggestionsResultInternal;\n\n/**\n * Hook for managing Tambo AI suggestions in a thread\n *\n * @param options - Configuration options for suggestion generation\n * @returns Object containing suggestions state and control functions\n */\nexport function useTamboSuggestions(\n options: useTamboSuggestionsOptions = {},\n): useTamboSuggestionsResult {\n const { maxSuggestions = 3 } = options;\n const { thread } = useTamboThread();\n const { sendThreadMessage } = useTambo();\n const tamboClient = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n\n const [selectedSuggestionId, setSelectedSuggestionId] = useState<\n string | null\n >(null);\n const { setValue: setInputValue } = useTamboThreadInput();\n\n const latestMessage = thread.messages[thread.messages.length - 1];\n const isLatestFromTambo = latestMessage?.role === \"assistant\";\n const latestMessageId = latestMessage?.id;\n\n // Reset selected suggestion when the message changes\n useEffect(() => {\n setSelectedSuggestionId(null);\n }, [latestMessageId]);\n\n // Use React Query to fetch suggestions when a new hydra message is received\n const suggestionsResult = useTamboQuery({\n // Only include latestMessageId in the queryKey if the message is from hydra\n queryKey: [\"suggestions\", isLatestFromTambo ? latestMessageId : null],\n queryFn: async () => {\n if (!latestMessageId || !isLatestFromTambo) {\n return [];\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n );\n },\n // Only run the query if we have a valid message from hydra\n enabled: Boolean(latestMessageId && isLatestFromTambo),\n // Don't refetch on window focus or reconnect\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n // Don't retry on failure\n retry: false,\n });\n\n // Accept suggestion mutation\n const acceptMutationState = useTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >({\n mutationFn: async ({ suggestion, shouldSubmit = false }) => {\n const validation = validateInput(suggestion.detailedSuggestion);\n if (!validation.isValid) {\n if (validation.error) {\n throw validation.error;\n }\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n if (shouldSubmit) {\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n });\n } else {\n setInputValue(validation.sanitizedInput);\n }\n setSelectedSuggestionId(suggestion.id);\n },\n });\n\n // Generate suggestions mutation\n const generateMutationState = useTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >({\n mutationFn: async (abortController: AbortController) => {\n if (!latestMessageId || !isLatestFromTambo) {\n return undefined;\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n { signal: abortController.signal },\n );\n },\n // Don't retry on failure\n retry: false,\n });\n\n // Use the query data if available, otherwise use the mutation data\n // Only return suggestions if the latest message is from hydra\n const suggestions = isLatestFromTambo\n ? (suggestionsResult.data ?? generateMutationState.data ?? [])\n : [];\n\n return {\n suggestions,\n accept: acceptMutationState.mutateAsync,\n selectedSuggestionId,\n acceptResult: acceptMutationState,\n generateResult: generateMutationState,\n suggestionsResult,\n ...combineMutationResults(acceptMutationState, generateMutationState),\n };\n}\n"]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AG,iBAAiB;QACnC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;QACL,WAAW;QACX,MAAM,EAAE,mBAAmB,CAAC,WAAW;QACvC,oBAAoB;QACpB,YAAY,EAAE,mBAAmB;QACjC,cAAc,EAAE,qBAAqB;QACrC,iBAAiB;QACjB,GAAG,sBAAsB,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { useEffect, useState } from \"react\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTambo } from \"../providers/tambo-provider\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport {\n CombinedMutationResult,\n combineMutationResults,\n} from \"../util/query-utils\";\nimport { getAvailableComponents } from \"../util/registry\";\nimport {\n UseTamboMutationResult,\n UseTamboQueryResult,\n useTamboMutationResult,\n useTamboQuery,\n} from \"./react-query-hooks\";\nimport { INPUT_ERROR_MESSAGES, useTamboThreadInput } from \"./use-thread-input\";\n\n/**\n * Configuration options for the useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsOptions {\n /** Maximum number of suggestions to generate (1-10, default 3) */\n maxSuggestions?: number;\n}\n\n/**\n * Return value interface for useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsResultInternal {\n /** List of available suggestions (also available in generateResult.data) */\n suggestions: TamboAI.Beta.Threads.Suggestion[];\n /** ID of the currently selected suggestion */\n selectedSuggestionId: string | null;\n /**\n * Accept and apply a suggestion (also available in acceptResult.mutateAsync)\n * @param suggestion - The suggestion to accept\n * @param shouldSubmit - Whether to automatically submit after accepting (default: false)\n */\n accept: (acceptOptions: {\n suggestion: TamboAI.Beta.Threads.Suggestion;\n shouldSubmit?: boolean;\n }) => Promise<void>;\n\n /** Result and network state for accepting a suggestion */\n acceptResult: UseTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >;\n\n /** Result and network state for generating suggestions */\n generateResult: UseTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >;\n\n /** The full suggestions query object from React Query */\n suggestionsResult: UseTamboQueryResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error\n >;\n}\n\ntype useTamboSuggestionsResult = CombinedMutationResult<any, Error> &\n useTamboSuggestionsResultInternal;\n\n/**\n * Hook for managing Tambo AI suggestions in a thread\n * @param options - Configuration options for suggestion generation\n * @returns Object containing suggestions state and control functions\n */\nexport function useTamboSuggestions(\n options: useTamboSuggestionsOptions = {},\n): useTamboSuggestionsResult {\n const { maxSuggestions = 3 } = options;\n const { thread } = useTamboThread();\n const { sendThreadMessage } = useTambo();\n const tamboClient = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n\n const [selectedSuggestionId, setSelectedSuggestionId] = useState<\n string | null\n >(null);\n const { setValue: setInputValue } = useTamboThreadInput();\n\n const latestMessage = thread.messages[thread.messages.length - 1];\n const isLatestFromTambo = latestMessage?.role === \"assistant\";\n const latestMessageId = latestMessage?.id;\n\n // Reset selected suggestion when the message changes\n useEffect(() => {\n setSelectedSuggestionId(null);\n }, [latestMessageId]);\n\n // Use React Query to fetch suggestions when a new hydra message is received\n const suggestionsResult = useTamboQuery({\n // Only include latestMessageId in the queryKey if the message is from hydra\n queryKey: [\"suggestions\", isLatestFromTambo ? latestMessageId : null],\n queryFn: async () => {\n if (!latestMessageId || !isLatestFromTambo) {\n return [];\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n );\n },\n // Only run the query if we have a valid message from hydra\n enabled: Boolean(latestMessageId && isLatestFromTambo),\n // Don't refetch on window focus or reconnect\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n // Don't retry on failure\n retry: false,\n });\n\n // Accept suggestion mutation\n const acceptMutationState = useTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >({\n mutationFn: async ({ suggestion, shouldSubmit = false }) => {\n const validation = validateInput(suggestion.detailedSuggestion);\n if (!validation.isValid) {\n if (validation.error) {\n throw validation.error;\n }\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n if (shouldSubmit) {\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n });\n } else {\n setInputValue(validation.sanitizedInput);\n }\n setSelectedSuggestionId(suggestion.id);\n },\n });\n\n // Generate suggestions mutation\n const generateMutationState = useTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >({\n mutationFn: async (abortController: AbortController) => {\n if (!latestMessageId || !isLatestFromTambo) {\n return undefined;\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n { signal: abortController.signal },\n );\n },\n // Don't retry on failure\n retry: false,\n });\n\n // Use the query data if available, otherwise use the mutation data\n // Only return suggestions if the latest message is from hydra\n const suggestions = isLatestFromTambo\n ? (suggestionsResult.data ?? generateMutationState.data ?? [])\n : [];\n\n return {\n suggestions,\n accept: acceptMutationState.mutateAsync,\n selectedSuggestionId,\n acceptResult: acceptMutationState,\n generateResult: generateMutationState,\n suggestionsResult,\n ...combineMutationResults(acceptMutationState, generateMutationState),\n };\n}\n"]}
@@ -1,10 +1,39 @@
1
- /**
2
- * Get the threads for the specified project and optional context key.
3
- */
4
- export declare function useTamboThreads({ projectId, contextKey, }?: {
1
+ interface UseTamboThreadListConfig {
2
+ /**
3
+ * The projectId to get the threads for. If not provided, the current project
4
+ * will be used.
5
+ */
6
+ projectId?: string;
7
+ /**
8
+ * The context key to get the threads for. If not provided, all threads for
9
+ * the project will be returned.
10
+ */
11
+ contextKey?: string;
12
+ }
13
+ interface UseTamboThreadListConfig {
14
+ /**
15
+ * The projectId to get the threads for. If not provided, the current project
16
+ * will be used.
17
+ */
5
18
  projectId?: string;
19
+ /**
20
+ * The context key to get the threads for. If not provided, all threads for
21
+ * the project will be returned.
22
+ */
6
23
  contextKey?: string;
7
- }): import("@tanstack/query-core").QueryObserverRefetchErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverSuccessResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverLoadingErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPendingResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPlaceholderResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | {
24
+ }
25
+ /**
26
+ * Get all the threads for the specified project.
27
+ *
28
+ * If contextKey is empty, then all threads for the project will be returned.
29
+ * If contextKey is not empty, then only the threads for the specified context
30
+ * key will be returned.
31
+ * @param config - The config for the useTamboThreadList hook
32
+ * @param config.projectId - The projectId to get the threads for
33
+ * @param config.contextKey - The context key to get the threads for
34
+ * @returns The threads for the specified project and optional context key
35
+ */
36
+ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTamboThreadListConfig): import("@tanstack/query-core").QueryObserverRefetchErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverSuccessResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverLoadingErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPendingResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPlaceholderResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | {
8
37
  error: Error;
9
38
  isError: true;
10
39
  isPending: false;
@@ -135,4 +164,5 @@ export declare function useTamboThreads({ projectId, contextKey, }?: {
135
164
  promise: Promise<string>;
136
165
  data: null;
137
166
  };
167
+ export {};
138
168
  //# sourceMappingURL=use-tambo-threads.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,UAAU,GACX,GAAE;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBL"}
1
+ {"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAGA,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,EACT,UAAU,GACX,GAAE,wBAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyB/B"}
@@ -1,9 +1,17 @@
1
1
  import { useTamboClient } from "../providers/tambo-client-provider";
2
2
  import { useTamboQuery } from "./react-query-hooks";
3
3
  /**
4
- * Get the threads for the specified project and optional context key.
4
+ * Get all the threads for the specified project.
5
+ *
6
+ * If contextKey is empty, then all threads for the project will be returned.
7
+ * If contextKey is not empty, then only the threads for the specified context
8
+ * key will be returned.
9
+ * @param config - The config for the useTamboThreadList hook
10
+ * @param config.projectId - The projectId to get the threads for
11
+ * @param config.contextKey - The context key to get the threads for
12
+ * @returns The threads for the specified project and optional context key
5
13
  */
6
- export function useTamboThreads({ projectId, contextKey, } = {}) {
14
+ export function useTamboThreadList({ projectId, contextKey, } = {}) {
7
15
  const client = useTamboClient();
8
16
  const { data: queriedProjectId, ...projectIdState } = useTamboQuery({
9
17
  queryKey: ["projectId"],
@@ -1 +1 @@
1
- {"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,SAAS,EACT,UAAU,MAIR,EAAE;IACJ,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa,CAAC;QAClE,QAAQ,EAAE,CAAC,WAAW,CAAC;QACvB,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,SAAS,IAAI,gBAAgB,CAAC;IAEvD,MAAM,WAAW,GAAG,aAAa,CAAC;QAChC,OAAO,EAAE,CAAC,CAAC,gBAAgB;QAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,CAAC;QACnD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAClE,UAAU;aACX,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTamboQuery } from \"./react-query-hooks\";\n\n/**\n * Get the threads for the specified project and optional context key.\n */\nexport function useTamboThreads({\n projectId,\n contextKey,\n}: {\n projectId?: string;\n contextKey?: string;\n} = {}) {\n const client = useTamboClient();\n const { data: queriedProjectId, ...projectIdState } = useTamboQuery({\n queryKey: [\"projectId\"],\n queryFn: async () => {\n return (await client.beta.projects.getCurrent()).id;\n },\n });\n const currentProjectId = projectId ?? queriedProjectId;\n\n const threadState = useTamboQuery({\n enabled: !!currentProjectId,\n queryKey: [\"threads\", currentProjectId, contextKey],\n queryFn: async () => {\n if (!currentProjectId) {\n return null;\n }\n const threadIter = await client.beta.threads.list(currentProjectId, {\n contextKey,\n });\n return threadIter;\n },\n });\n\n return currentProjectId ? threadState : { data: null, ...projectIdState };\n}\n"]}
1
+ {"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA4BpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,SAAS,EACT,UAAU,MACkB,EAAE;IAC9B,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa,CAAC;QAClE,QAAQ,EAAE,CAAC,WAAW,CAAC;QACvB,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,SAAS,IAAI,gBAAgB,CAAC;IAEvD,MAAM,WAAW,GAAG,aAAa,CAAC;QAChC,OAAO,EAAE,CAAC,CAAC,gBAAgB;QAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,CAAC;QACnD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAClE,UAAU;aACX,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTamboQuery } from \"./react-query-hooks\";\n\ninterface UseTamboThreadListConfig {\n /**\n * The projectId to get the threads for. If not provided, the current project\n * will be used.\n */\n projectId?: string;\n /**\n * The context key to get the threads for. If not provided, all threads for\n * the project will be returned.\n */\n contextKey?: string;\n}\n\ninterface UseTamboThreadListConfig {\n /**\n * The projectId to get the threads for. If not provided, the current project\n * will be used.\n */\n projectId?: string;\n /**\n * The context key to get the threads for. If not provided, all threads for\n * the project will be returned.\n */\n contextKey?: string;\n}\n\n/**\n * Get all the threads for the specified project.\n *\n * If contextKey is empty, then all threads for the project will be returned.\n * If contextKey is not empty, then only the threads for the specified context\n * key will be returned.\n * @param config - The config for the useTamboThreadList hook\n * @param config.projectId - The projectId to get the threads for\n * @param config.contextKey - The context key to get the threads for\n * @returns The threads for the specified project and optional context key\n */\nexport function useTamboThreadList({\n projectId,\n contextKey,\n}: UseTamboThreadListConfig = {}) {\n const client = useTamboClient();\n const { data: queriedProjectId, ...projectIdState } = useTamboQuery({\n queryKey: [\"projectId\"],\n queryFn: async () => {\n return (await client.beta.projects.getCurrent()).id;\n },\n });\n const currentProjectId = projectId ?? queriedProjectId;\n\n const threadState = useTamboQuery({\n enabled: !!currentProjectId,\n queryKey: [\"threads\", currentProjectId, contextKey],\n queryFn: async () => {\n if (!currentProjectId) {\n return null;\n }\n const threadIter = await client.beta.threads.list(currentProjectId, {\n contextKey,\n });\n return threadIter;\n },\n });\n\n return currentProjectId ? threadState : { data: null, ...projectIdState };\n}\n"]}
@@ -43,7 +43,6 @@ export type UseThreadInput = UseThreadInputInternal & UseMutationResult<void, Er
43
43
  }>;
44
44
  /**
45
45
  * Hook for managing thread message input state and submission
46
- *
47
46
  * @returns Interface for managing thread input state and submission
48
47
  */
49
48
  export declare function useTamboThreadInput(contextKey?: string): UseThreadInput;
@@ -1 +1 @@
1
- {"version":3,"file":"use-thread-input.d.ts","sourceRoot":"","sources":["../../src/hooks/use-thread-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;IAC/B,kDAAkD;;IAElD,0CAA0C;;IAE1C,qDAAqD;;IAErD,yCAAyC;;CAEjC,CAAC;AAEX;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AACD,MAAM,MAAM,cAAc,GAAG,sBAAsB,GACjD,iBAAiB,CACf,IAAI,EACJ,KAAK,EACL;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAClD,CAAC;AAEJ;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAwCvE"}
1
+ {"version":3,"file":"use-thread-input.d.ts","sourceRoot":"","sources":["../../src/hooks/use-thread-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;IAC/B,kDAAkD;;IAElD,0CAA0C;;IAE1C,qDAAqD;;IAErD,yCAAyC;;CAEjC,CAAC;AAEX;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AACD,MAAM,MAAM,cAAc,GAAG,sBAAsB,GACjD,iBAAiB,CACf,IAAI,EACJ,KAAK,EACL;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAClD,CAAC;AAEJ;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAwCvE"}
@@ -20,7 +20,6 @@ export const INPUT_ERROR_MESSAGES = {
20
20
  };
21
21
  /**
22
22
  * Hook for managing thread message input state and submission
23
- *
24
23
  * @returns Interface for managing thread input state and submission
25
24
  */
26
25
  export function useTamboThreadInput(contextKey) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-thread-input.js","sourceRoot":"","sources":["../../src/hooks/use-thread-input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kDAAkD;IAClD,KAAK,EAAE,yBAAyB;IAChC,0CAA0C;IAC1C,OAAO,EAAE,6CAA6C;IACtD,qDAAqD;IACrD,MAAM,EAAE,gCAAgC;IACxC,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";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport { useTamboMutation } from \"./react-query-hooks\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n /** Error when attempting to submit empty input */\n EMPTY: \"Message cannot be empty\",\n /** Error when network connection fails */\n NETWORK: \"Network error. Please check your connection\",\n /** Error when server fails to process the request */\n SERVER: \"Server error. Please try again\",\n /** Error when input format is invalid */\n VALIDATION: \"Invalid message format\",\n} as const;\n\n/**\n * Interface for the thread input hook return value\n * Provides all necessary functions and state for managing thread input\n */\ninterface UseThreadInputInternal {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: string) => void;\n /**\n * Function to submit the current input value\n * Validates input, handles errors, and cleans up state after submission\n * @throws {ThreadInputError} If submission fails\n * @returns Promise that resolves when submission is complete\n */\n submit: (options?: {\n contextKey?: string;\n streamResponse?: boolean;\n }) => Promise<void>;\n}\nexport type UseThreadInput = UseThreadInputInternal &\n UseMutationResult<\n void,\n Error,\n { contextKey?: string; streamResponse?: boolean }\n >;\n\n/**\n * Hook for managing thread message input state and submission\n *\n * @returns Interface for managing thread input state and submission\n */\nexport function useTamboThreadInput(contextKey?: string): UseThreadInput {\n const { thread, inputValue, setInputValue, sendThreadMessage } =\n useTamboThread();\n\n const submit = useCallback(\n async ({\n contextKey: submitContextKey,\n streamResponse,\n }: { contextKey?: string; streamResponse?: boolean } = {}) => {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n contextKey: submitContextKey ?? contextKey ?? undefined,\n streamResponse: streamResponse,\n });\n setInputValue(\"\");\n },\n [inputValue, sendThreadMessage, thread.id, contextKey, setInputValue],\n );\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submit,\n });\n\n return {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n } as UseThreadInput;\n}\n"]}
1
+ {"version":3,"file":"use-thread-input.js","sourceRoot":"","sources":["../../src/hooks/use-thread-input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kDAAkD;IAClD,KAAK,EAAE,yBAAyB;IAChC,0CAA0C;IAC1C,OAAO,EAAE,6CAA6C;IACtD,qDAAqD;IACrD,MAAM,EAAE,gCAAgC;IACxC,yCAAyC;IACzC,UAAU,EAAE,wBAAwB;CAC5B,CAAC;AAgCX;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAmB;IACrD,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAC5D,cAAc,EAAE,CAAC;IAEnB,MAAM,MAAM,GAAG,WAAW,CACxB,KAAK,EAAE,EACL,UAAU,EAAE,gBAAgB,EAC5B,cAAc,MACuC,EAAE,EAAE,EAAE;QAC3D,MAAM,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACxB,MAAM,IAAI,gBAAgB,CACxB,0BAA0B,UAAU,CAAC,KAAK,IAAI,oBAAoB,CAAC,UAAU,EAAE,EAC/E,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAC5B,CAAC;QACJ,CAAC;QAED,MAAM,iBAAiB,CAAC,UAAU,CAAC,cAAc,EAAE;YACjD,QAAQ,EAAE,MAAM,CAAC,EAAE;YACnB,UAAU,EAAE,gBAAgB,IAAI,UAAU,IAAI,SAAS;YACvD,cAAc,EAAE,cAAc;SAC/B,CAAC,CAAC;QACH,aAAa,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,UAAU,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,aAAa,CAAC,CACtE,CAAC;IACF,MAAM,EACJ,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,aAAa,EACrB,GAAG,aAAa,EACjB,GAAG,gBAAgB,CAAC;QACnB,UAAU,EAAE,MAAM;KACnB,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,aAAa;QAChB,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,aAAa;QACvB,MAAM,EAAE,WAAW;KACF,CAAC;AACtB,CAAC","sourcesContent":["import { UseMutationResult } from \"@tanstack/react-query\";\nimport { useCallback } from \"react\";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport { useTamboMutation } from \"./react-query-hooks\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n /** Error when attempting to submit empty input */\n EMPTY: \"Message cannot be empty\",\n /** Error when network connection fails */\n NETWORK: \"Network error. Please check your connection\",\n /** Error when server fails to process the request */\n SERVER: \"Server error. Please try again\",\n /** Error when input format is invalid */\n VALIDATION: \"Invalid message format\",\n} as const;\n\n/**\n * Interface for the thread input hook return value\n * Provides all necessary functions and state for managing thread input\n */\ninterface UseThreadInputInternal {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: string) => void;\n /**\n * Function to submit the current input value\n * Validates input, handles errors, and cleans up state after submission\n * @throws {ThreadInputError} If submission fails\n * @returns Promise that resolves when submission is complete\n */\n submit: (options?: {\n contextKey?: string;\n streamResponse?: boolean;\n }) => Promise<void>;\n}\nexport type UseThreadInput = UseThreadInputInternal &\n UseMutationResult<\n void,\n Error,\n { contextKey?: string; streamResponse?: boolean }\n >;\n\n/**\n * Hook for managing thread message input state and submission\n * @returns Interface for managing thread input state and submission\n */\nexport function useTamboThreadInput(contextKey?: string): UseThreadInput {\n const { thread, inputValue, setInputValue, sendThreadMessage } =\n useTamboThread();\n\n const submit = useCallback(\n async ({\n contextKey: submitContextKey,\n streamResponse,\n }: { contextKey?: string; streamResponse?: boolean } = {}) => {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n contextKey: submitContextKey ?? contextKey ?? undefined,\n streamResponse: streamResponse,\n });\n setInputValue(\"\");\n },\n [inputValue, sendThreadMessage, thread.id, contextKey, setInputValue],\n );\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submit,\n });\n\n return {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n } as UseThreadInput;\n}\n"]}
package/esm/index.d.ts CHANGED
@@ -4,10 +4,10 @@ export { TamboMessageProvider, useTamboCurrentMessage, useTamboMessageContext, }
4
4
  export { useTamboStreamingProps } from "./hooks/use-streaming-props";
5
5
  export * from "./hooks/use-suggestions";
6
6
  export { useTamboThreadInput } from "./hooks/use-thread-input";
7
- export * from "./providers";
7
+ export { TamboClientProvider, TamboComponentProvider, TamboProvider, TamboThreadProvider, useTambo, useTamboClient, useTamboThread, type TamboComponent, type TamboRegistryContext, } from "./providers";
8
8
  export type { APIError, RateLimitError, TamboAIError, } from "@tambo-ai/typescript-sdk";
9
9
  export type { Suggestion, SuggestionGenerateParams, SuggestionGenerateResponse, SuggestionListResponse, } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
10
- export { useTamboThreads } from "./hooks/use-tambo-threads";
10
+ export { useTamboThreadList } from "./hooks/use-tambo-threads";
11
11
  export { type ComponentContextToolMetadata, type ComponentRegistry, type ParameterSpec, type RegisteredComponent, type TamboTool, } from "./model/component-metadata";
12
12
  export { GenerationStage, type TamboThreadMessage, } from "./model/generate-component-response";
13
13
  export { type TamboThread } from "./model/tambo-thread";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,cAAc,aAAa,CAAC;AAG5B,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
package/esm/index.js CHANGED
@@ -5,7 +5,7 @@ export { useTamboStreamingProps } from "./hooks/use-streaming-props";
5
5
  export * from "./hooks/use-suggestions";
6
6
  export { useTamboThreadInput } from "./hooks/use-thread-input";
7
7
  // Re-export provider components
8
- export * from "./providers";
9
- export { useTamboThreads } from "./hooks/use-tambo-threads";
8
+ export { TamboClientProvider, TamboComponentProvider, TamboProvider, TamboThreadProvider, useTambo, useTamboClient, useTamboThread, } from "./providers";
9
+ export { useTamboThreadList } from "./hooks/use-tambo-threads";
10
10
  export { GenerationStage, } from "./model/generate-component-response";
11
11
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,cAAc,aAAa,CAAC;AAc5B,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAQ5D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport * from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreads } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,GAGf,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n"]}
@@ -38,7 +38,8 @@ export interface TamboComponent {
38
38
  name: string;
39
39
  /** The description of the component */
40
40
  description: string;
41
- /** The React component to render.
41
+ /**
42
+ * The React component to render.
42
43
  *
43
44
  * Make sure to pass the Component itself, not an instance of the component. For example,
44
45
  * if you have a component like this:
@@ -57,11 +58,13 @@ export interface TamboComponent {
57
58
  * ```
58
59
  */
59
60
  component: ComponentType<any>;
60
- /** A zod schema for the component props. (Recommended)
61
+ /**
62
+ * A zod schema for the component props. (Recommended)
61
63
  * Either this or propsDefinition must be provided, but not both.
62
64
  */
63
65
  propsSchema?: z.ZodTypeAny;
64
- /** The props definition of the component as a JSON object.
66
+ /**
67
+ * The props definition of the component as a JSON object.
65
68
  * Either this or propsSchema must be provided, but not both.
66
69
  */
67
70
  propsDefinition?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"component-metadata.d.ts","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AACtD,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,GAAG;IACn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","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns>;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /** The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /** A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny;\n /** The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
1
+ {"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns>;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import { ReactElement } from "react";
3
- /** An extension of the TamboAI.Beta.Threads.ThreadMessage type that includes a
4
- * renderedComponent */
3
+ /**
4
+ * An extension of the TamboAI.Beta.Threads.ThreadMessage type that includes a
5
+ * renderedComponent
6
+ */
5
7
  export interface TamboThreadMessage extends TamboAI.Beta.Threads.ThreadMessage {
6
8
  renderedComponent?: ReactElement | null;
7
9
  }
@@ -14,5 +16,10 @@ export declare enum GenerationStage {
14
16
  COMPLETE = "COMPLETE",
15
17
  ERROR = "ERROR"
16
18
  }
19
+ /**
20
+ * Checks if the generation stage is in a state where it can accept user input.
21
+ * @param generationStage - The generation stage to check
22
+ * @returns True if the generation stage is idle, false otherwise
23
+ */
17
24
  export declare function isIdleStage(generationStage: GenerationStage): boolean;
18
25
  //# sourceMappingURL=generate-component-response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-component-response.d.ts","sourceRoot":"","sources":["../../src/model/generate-component-response.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC;uBACuB;AACvB,MAAM,WAAW,kBAAmB,SAAQ,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa;IAC5E,iBAAiB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACzC;AAED,oBAAY,eAAe;IACzB,IAAI,SAAS;IACb,kBAAkB,uBAAuB;IACzC,gBAAgB,qBAAqB;IACrC,mBAAmB,wBAAwB;IAC3C,kBAAkB,uBAAuB;IACzC,QAAQ,aAAa;IACrB,KAAK,UAAU;CAChB;AACD,wBAAgB,WAAW,CAAC,eAAe,EAAE,eAAe,WAM3D"}
1
+ {"version":3,"file":"generate-component-response.d.ts","sourceRoot":"","sources":["../../src/model/generate-component-response.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa;IAC5E,iBAAiB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACzC;AAED,oBAAY,eAAe;IACzB,IAAI,SAAS;IACb,kBAAkB,uBAAuB;IACzC,gBAAgB,qBAAqB;IACrC,mBAAmB,wBAAwB;IAC3C,kBAAkB,uBAAuB;IACzC,QAAQ,aAAa;IACrB,KAAK,UAAU;CAChB;AACD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,eAAe,WAM3D"}
@@ -8,6 +8,11 @@ export var GenerationStage;
8
8
  GenerationStage["COMPLETE"] = "COMPLETE";
9
9
  GenerationStage["ERROR"] = "ERROR";
10
10
  })(GenerationStage || (GenerationStage = {}));
11
+ /**
12
+ * Checks if the generation stage is in a state where it can accept user input.
13
+ * @param generationStage - The generation stage to check
14
+ * @returns True if the generation stage is idle, false otherwise
15
+ */
11
16
  export function isIdleStage(generationStage) {
12
17
  return [
13
18
  GenerationStage.IDLE,
@@ -1 +1 @@
1
- {"version":3,"file":"generate-component-response.js","sourceRoot":"","sources":["../../src/model/generate-component-response.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,4DAAyC,CAAA;IACzC,wDAAqC,CAAA;IACrC,8DAA2C,CAAA;IAC3C,4DAAyC,CAAA;IACzC,wCAAqB,CAAA;IACrB,kCAAe,CAAA;AACjB,CAAC,EARW,eAAe,KAAf,eAAe,QAQ1B;AACD,MAAM,UAAU,WAAW,CAAC,eAAgC;IAC1D,OAAO;QACL,eAAe,CAAC,IAAI;QACpB,eAAe,CAAC,QAAQ;QACxB,eAAe,CAAC,KAAK;KACtB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { ReactElement } from \"react\";\n\n/** An extension of the TamboAI.Beta.Threads.ThreadMessage type that includes a\n * renderedComponent */\nexport interface TamboThreadMessage extends TamboAI.Beta.Threads.ThreadMessage {\n renderedComponent?: ReactElement | null;\n}\n\nexport enum GenerationStage {\n IDLE = \"IDLE\",\n CHOOSING_COMPONENT = \"CHOOSING_COMPONENT\",\n FETCHING_CONTEXT = \"FETCHING_CONTEXT\",\n HYDRATING_COMPONENT = \"HYDRATING_COMPONENT\",\n STREAMING_RESPONSE = \"STREAMING_RESPONSE\",\n COMPLETE = \"COMPLETE\",\n ERROR = \"ERROR\",\n}\nexport function isIdleStage(generationStage: GenerationStage) {\n return [\n GenerationStage.IDLE,\n GenerationStage.COMPLETE,\n GenerationStage.ERROR,\n ].includes(generationStage);\n}\n"]}
1
+ {"version":3,"file":"generate-component-response.js","sourceRoot":"","sources":["../../src/model/generate-component-response.ts"],"names":[],"mappings":"AAWA,MAAM,CAAN,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,4DAAyC,CAAA;IACzC,wDAAqC,CAAA;IACrC,8DAA2C,CAAA;IAC3C,4DAAyC,CAAA;IACzC,wCAAqB,CAAA;IACrB,kCAAe,CAAA;AACjB,CAAC,EARW,eAAe,KAAf,eAAe,QAQ1B;AACD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,eAAgC;IAC1D,OAAO;QACL,eAAe,CAAC,IAAI;QACpB,eAAe,CAAC,QAAQ;QACxB,eAAe,CAAC,KAAK;KACtB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { ReactElement } from \"react\";\n\n/**\n * An extension of the TamboAI.Beta.Threads.ThreadMessage type that includes a\n * renderedComponent\n */\nexport interface TamboThreadMessage extends TamboAI.Beta.Threads.ThreadMessage {\n renderedComponent?: ReactElement | null;\n}\n\nexport enum GenerationStage {\n IDLE = \"IDLE\",\n CHOOSING_COMPONENT = \"CHOOSING_COMPONENT\",\n FETCHING_CONTEXT = \"FETCHING_CONTEXT\",\n HYDRATING_COMPONENT = \"HYDRATING_COMPONENT\",\n STREAMING_RESPONSE = \"STREAMING_RESPONSE\",\n COMPLETE = \"COMPLETE\",\n ERROR = \"ERROR\",\n}\n/**\n * Checks if the generation stage is in a state where it can accept user input.\n * @param generationStage - The generation stage to check\n * @returns True if the generation stage is idle, false otherwise\n */\nexport function isIdleStage(generationStage: GenerationStage) {\n return [\n GenerationStage.IDLE,\n GenerationStage.COMPLETE,\n GenerationStage.ERROR,\n ].includes(generationStage);\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import { TamboThreadMessage } from "./generate-component-response";
3
- /** An extension of the TamboAI.Beta.Thread type that includes
4
- * messages with renderedComponent */
3
+ /**
4
+ * An extension of the TamboAI.Beta.Thread type that includes
5
+ * messages with renderedComponent
6
+ */
5
7
  export interface TamboThread extends TamboAI.Beta.Thread {
6
8
  messages: TamboThreadMessage[];
7
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread.d.ts","sourceRoot":"","sources":["../../src/model/tambo-thread.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE;qCACqC;AACrC,MAAM,WAAW,WAAY,SAAQ,OAAO,CAAC,IAAI,CAAC,MAAM;IACtD,QAAQ,EAAE,kBAAkB,EAAE,CAAC;CAChC"}
1
+ {"version":3,"file":"tambo-thread.d.ts","sourceRoot":"","sources":["../../src/model/tambo-thread.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,OAAO,CAAC,IAAI,CAAC,MAAM;IACtD,QAAQ,EAAE,kBAAkB,EAAE,CAAC;CAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread.js","sourceRoot":"","sources":["../../src/model/tambo-thread.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { TamboThreadMessage } from \"./generate-component-response\";\n\n/** An extension of the TamboAI.Beta.Thread type that includes\n * messages with renderedComponent */\nexport interface TamboThread extends TamboAI.Beta.Thread {\n messages: TamboThreadMessage[];\n}\n"]}
1
+ {"version":3,"file":"tambo-thread.js","sourceRoot":"","sources":["../../src/model/tambo-thread.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { TamboThreadMessage } from \"./generate-component-response\";\n\n/**\n * An extension of the TamboAI.Beta.Thread type that includes\n * messages with renderedComponent\n */\nexport interface TamboThread extends TamboAI.Beta.Thread {\n messages: TamboThreadMessage[];\n}\n"]}
@@ -3,5 +3,10 @@ export interface ValidationResult {
3
3
  error?: Error;
4
4
  sanitizedInput: string;
5
5
  }
6
+ /**
7
+ * Validates the input of a message. Makes sure the message is not empty and is not too long.
8
+ * @param input - The input to validate
9
+ * @returns The validation result
10
+ */
6
11
  export declare function validateInput(input: string): ValidationResult;
7
12
  //# sourceMappingURL=validate-input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-input.d.ts","sourceRoot":"","sources":["../../src/model/validate-input.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB;AAGD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAwB7D"}
1
+ {"version":3,"file":"validate-input.d.ts","sourceRoot":"","sources":["../../src/model/validate-input.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAwB7D"}
@@ -1,4 +1,8 @@
1
- // TODO(future): Consider adding more validation rules if needed
1
+ /**
2
+ * Validates the input of a message. Makes sure the message is not empty and is not too long.
3
+ * @param input - The input to validate
4
+ * @returns The validation result
5
+ */
2
6
  export function validateInput(input) {
3
7
  const trimmed = input.trim();
4
8
  if (trimmed.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"validate-input.js","sourceRoot":"","sources":["../../src/model/validate-input.ts"],"names":[],"mappings":"AAMA,gEAAgE;AAChE,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CAAC,yBAAyB,CAAC;YAC3C,cAAc,EAAE,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,+CAA+C;IAC/C,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QAC3B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CAAC,4CAA4C,CAAC;YAC9D,cAAc,EAAE,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,OAAO;KACxB,CAAC;AACJ,CAAC","sourcesContent":["export interface ValidationResult {\n isValid: boolean;\n error?: Error;\n sanitizedInput: string;\n}\n\n// TODO(future): Consider adding more validation rules if needed\nexport function validateInput(input: string): ValidationResult {\n const trimmed = input.trim();\n\n if (trimmed.length === 0) {\n return {\n isValid: false,\n error: new Error(\"Message cannot be empty\"),\n sanitizedInput: trimmed,\n };\n }\n\n // TODO(perf): Make this configurable if needed\n if (trimmed.length > 10000) {\n return {\n isValid: false,\n error: new Error(\"Message is too long (max 10000 characters)\"),\n sanitizedInput: trimmed,\n };\n }\n\n return {\n isValid: true,\n sanitizedInput: trimmed,\n };\n}\n"]}
1
+ {"version":3,"file":"validate-input.js","sourceRoot":"","sources":["../../src/model/validate-input.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CAAC,yBAAyB,CAAC;YAC3C,cAAc,EAAE,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,+CAA+C;IAC/C,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QAC3B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CAAC,4CAA4C,CAAC;YAC9D,cAAc,EAAE,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,OAAO;KACxB,CAAC;AACJ,CAAC","sourcesContent":["export interface ValidationResult {\n isValid: boolean;\n error?: Error;\n sanitizedInput: string;\n}\n\n/**\n * Validates the input of a message. Makes sure the message is not empty and is not too long.\n * @param input - The input to validate\n * @returns The validation result\n */\nexport function validateInput(input: string): ValidationResult {\n const trimmed = input.trim();\n\n if (trimmed.length === 0) {\n return {\n isValid: false,\n error: new Error(\"Message cannot be empty\"),\n sanitizedInput: trimmed,\n };\n }\n\n // TODO(perf): Make this configurable if needed\n if (trimmed.length > 10000) {\n return {\n isValid: false,\n error: new Error(\"Message is too long (max 10000 characters)\"),\n sanitizedInput: trimmed,\n };\n }\n\n return {\n isValid: true,\n sanitizedInput: trimmed,\n };\n}\n"]}