@tambo-ai/react 0.19.0 → 0.19.2

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 (173) hide show
  1. package/dist/hooks/react-query-hooks.d.ts +8 -0
  2. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  3. package/dist/hooks/react-query-hooks.js +8 -0
  4. package/dist/hooks/react-query-hooks.js.map +1 -1
  5. package/dist/hooks/use-component-state.d.ts +0 -3
  6. package/dist/hooks/use-component-state.d.ts.map +1 -1
  7. package/dist/hooks/use-component-state.js +8 -26
  8. package/dist/hooks/use-component-state.js.map +1 -1
  9. package/dist/hooks/use-current-message.d.ts +27 -7
  10. package/dist/hooks/use-current-message.d.ts.map +1 -1
  11. package/dist/hooks/use-current-message.js +27 -7
  12. package/dist/hooks/use-current-message.js.map +1 -1
  13. package/dist/hooks/use-streaming-props.d.ts +0 -2
  14. package/dist/hooks/use-streaming-props.d.ts.map +1 -1
  15. package/dist/hooks/use-streaming-props.js +2 -3
  16. package/dist/hooks/use-streaming-props.js.map +1 -1
  17. package/dist/hooks/use-suggestions.d.ts +0 -1
  18. package/dist/hooks/use-suggestions.d.ts.map +1 -1
  19. package/dist/hooks/use-suggestions.js +0 -1
  20. package/dist/hooks/use-suggestions.js.map +1 -1
  21. package/dist/hooks/use-tambo-threads.d.ts +35 -5
  22. package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
  23. package/dist/hooks/use-tambo-threads.js +9 -1
  24. package/dist/hooks/use-tambo-threads.js.map +1 -1
  25. package/dist/hooks/use-thread-input.d.ts +0 -1
  26. package/dist/hooks/use-thread-input.d.ts.map +1 -1
  27. package/dist/hooks/use-thread-input.js +0 -1
  28. package/dist/hooks/use-thread-input.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +9 -2
  32. package/dist/index.js.map +1 -1
  33. package/dist/model/component-metadata.d.ts +6 -3
  34. package/dist/model/component-metadata.d.ts.map +1 -1
  35. package/dist/model/component-metadata.js.map +1 -1
  36. package/dist/model/generate-component-response.d.ts +9 -2
  37. package/dist/model/generate-component-response.d.ts.map +1 -1
  38. package/dist/model/generate-component-response.js +5 -0
  39. package/dist/model/generate-component-response.js.map +1 -1
  40. package/dist/model/tambo-thread.d.ts +4 -2
  41. package/dist/model/tambo-thread.d.ts.map +1 -1
  42. package/dist/model/tambo-thread.js.map +1 -1
  43. package/dist/model/validate-input.d.ts +5 -0
  44. package/dist/model/validate-input.d.ts.map +1 -1
  45. package/dist/model/validate-input.js +5 -1
  46. package/dist/model/validate-input.js.map +1 -1
  47. package/dist/providers/tambo-client-provider.d.ts +31 -0
  48. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  49. package/dist/providers/tambo-client-provider.js +21 -0
  50. package/dist/providers/tambo-client-provider.js.map +1 -1
  51. package/dist/providers/tambo-component-provider.d.ts +12 -0
  52. package/dist/providers/tambo-component-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-component-provider.js +24 -0
  54. package/dist/providers/tambo-component-provider.js.map +1 -1
  55. package/dist/providers/tambo-provider.d.ts +18 -1
  56. package/dist/providers/tambo-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-provider.js +25 -2
  58. package/dist/providers/tambo-provider.js.map +1 -1
  59. package/dist/providers/tambo-registry-provider.d.ts +14 -1
  60. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  61. package/dist/providers/tambo-registry-provider.js +25 -0
  62. package/dist/providers/tambo-registry-provider.js.map +1 -1
  63. package/dist/providers/tambo-thread-provider.d.ts +25 -2
  64. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  65. package/dist/providers/tambo-thread-provider.js +32 -26
  66. package/dist/providers/tambo-thread-provider.js.map +1 -1
  67. package/dist/util/generate-component.d.ts +5 -1
  68. package/dist/util/generate-component.d.ts.map +1 -1
  69. package/dist/util/generate-component.js +5 -1
  70. package/dist/util/generate-component.js.map +1 -1
  71. package/dist/util/query-utils.d.ts +16 -0
  72. package/dist/util/query-utils.d.ts.map +1 -1
  73. package/dist/util/query-utils.js +16 -0
  74. package/dist/util/query-utils.js.map +1 -1
  75. package/dist/util/registry.d.ts +27 -1
  76. package/dist/util/registry.d.ts.map +1 -1
  77. package/dist/util/registry.js +29 -4
  78. package/dist/util/registry.js.map +1 -1
  79. package/dist/util/tool-caller.d.ts +6 -0
  80. package/dist/util/tool-caller.d.ts.map +1 -1
  81. package/dist/util/tool-caller.js +6 -0
  82. package/dist/util/tool-caller.js.map +1 -1
  83. package/esm/hooks/react-query-hooks.d.ts +8 -0
  84. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  85. package/esm/hooks/react-query-hooks.js +8 -0
  86. package/esm/hooks/react-query-hooks.js.map +1 -1
  87. package/esm/hooks/use-component-state.d.ts +0 -3
  88. package/esm/hooks/use-component-state.d.ts.map +1 -1
  89. package/esm/hooks/use-component-state.js +2 -23
  90. package/esm/hooks/use-component-state.js.map +1 -1
  91. package/esm/hooks/use-current-message.d.ts +27 -7
  92. package/esm/hooks/use-current-message.d.ts.map +1 -1
  93. package/esm/hooks/use-current-message.js +27 -7
  94. package/esm/hooks/use-current-message.js.map +1 -1
  95. package/esm/hooks/use-streaming-props.d.ts +0 -2
  96. package/esm/hooks/use-streaming-props.d.ts.map +1 -1
  97. package/esm/hooks/use-streaming-props.js +2 -3
  98. package/esm/hooks/use-streaming-props.js.map +1 -1
  99. package/esm/hooks/use-suggestions.d.ts +0 -1
  100. package/esm/hooks/use-suggestions.d.ts.map +1 -1
  101. package/esm/hooks/use-suggestions.js +0 -1
  102. package/esm/hooks/use-suggestions.js.map +1 -1
  103. package/esm/hooks/use-tambo-threads.d.ts +35 -5
  104. package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
  105. package/esm/hooks/use-tambo-threads.js +9 -1
  106. package/esm/hooks/use-tambo-threads.js.map +1 -1
  107. package/esm/hooks/use-thread-input.d.ts +0 -1
  108. package/esm/hooks/use-thread-input.d.ts.map +1 -1
  109. package/esm/hooks/use-thread-input.js +0 -1
  110. package/esm/hooks/use-thread-input.js.map +1 -1
  111. package/esm/index.d.ts +1 -1
  112. package/esm/index.d.ts.map +1 -1
  113. package/esm/index.js +1 -1
  114. package/esm/index.js.map +1 -1
  115. package/esm/model/component-metadata.d.ts +6 -3
  116. package/esm/model/component-metadata.d.ts.map +1 -1
  117. package/esm/model/component-metadata.js.map +1 -1
  118. package/esm/model/generate-component-response.d.ts +9 -2
  119. package/esm/model/generate-component-response.d.ts.map +1 -1
  120. package/esm/model/generate-component-response.js +5 -0
  121. package/esm/model/generate-component-response.js.map +1 -1
  122. package/esm/model/tambo-thread.d.ts +4 -2
  123. package/esm/model/tambo-thread.d.ts.map +1 -1
  124. package/esm/model/tambo-thread.js.map +1 -1
  125. package/esm/model/validate-input.d.ts +5 -0
  126. package/esm/model/validate-input.d.ts.map +1 -1
  127. package/esm/model/validate-input.js +5 -1
  128. package/esm/model/validate-input.js.map +1 -1
  129. package/esm/providers/tambo-client-provider.d.ts +31 -0
  130. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  131. package/esm/providers/tambo-client-provider.js +21 -0
  132. package/esm/providers/tambo-client-provider.js.map +1 -1
  133. package/esm/providers/tambo-component-provider.d.ts +12 -0
  134. package/esm/providers/tambo-component-provider.d.ts.map +1 -1
  135. package/esm/providers/tambo-component-provider.js +24 -0
  136. package/esm/providers/tambo-component-provider.js.map +1 -1
  137. package/esm/providers/tambo-provider.d.ts +18 -1
  138. package/esm/providers/tambo-provider.d.ts.map +1 -1
  139. package/esm/providers/tambo-provider.js +25 -2
  140. package/esm/providers/tambo-provider.js.map +1 -1
  141. package/esm/providers/tambo-registry-provider.d.ts +14 -1
  142. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  143. package/esm/providers/tambo-registry-provider.js +25 -0
  144. package/esm/providers/tambo-registry-provider.js.map +1 -1
  145. package/esm/providers/tambo-thread-provider.d.ts +25 -2
  146. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  147. package/esm/providers/tambo-thread-provider.js +32 -26
  148. package/esm/providers/tambo-thread-provider.js.map +1 -1
  149. package/esm/util/generate-component.d.ts +5 -1
  150. package/esm/util/generate-component.d.ts.map +1 -1
  151. package/esm/util/generate-component.js +5 -1
  152. package/esm/util/generate-component.js.map +1 -1
  153. package/esm/util/query-utils.d.ts +16 -0
  154. package/esm/util/query-utils.d.ts.map +1 -1
  155. package/esm/util/query-utils.js +16 -0
  156. package/esm/util/query-utils.js.map +1 -1
  157. package/esm/util/registry.d.ts +27 -1
  158. package/esm/util/registry.d.ts.map +1 -1
  159. package/esm/util/registry.js +28 -2
  160. package/esm/util/registry.js.map +1 -1
  161. package/esm/util/tool-caller.d.ts +6 -0
  162. package/esm/util/tool-caller.d.ts.map +1 -1
  163. package/esm/util/tool-caller.js +6 -0
  164. package/esm/util/tool-caller.js.map +1 -1
  165. package/package.json +4 -2
  166. package/dist/util/messages.d.ts +0 -3
  167. package/dist/util/messages.d.ts.map +0 -1
  168. package/dist/util/messages.js +0 -12
  169. package/dist/util/messages.js.map +0 -1
  170. package/esm/util/messages.d.ts +0 -3
  171. package/esm/util/messages.d.ts.map +0 -1
  172. package/esm/util/messages.js +0 -9
  173. package/esm/util/messages.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"query-utils.js","sourceRoot":"","sources":["../../src/util/query-utils.ts"],"names":[],"mappings":";;AAYA,wDAyBC;AAMD,kDAyCC;AAxED,SAAgB,sBAAsB,CACpC,OAAqD,EACrD,OAAqD;IAErD,CAAC;QACC,OAAO;YACL,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;YACjD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;YACjD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO;YAC3C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM;YACxC,QAAQ,EA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","sourcesContent":["import { UseMutationResult, UseQueryResult } from \"@tanstack/react-query\";\n\nexport type CombinedMutationResult<\n TData = unknown,\n TError = unknown,\n TVariables = unknown,\n TContext = unknown,\n> = Omit<\n UseMutationResult<TData, TError, TVariables, TContext>,\n \"mutate\" | \"mutateAsync\" | \"reset\" | \"data\" | \"variables\" | \"context\"\n>;\n\nexport function combineMutationResults<TData1, TData2, TError1, TError2>(\n resultA: UseMutationResult<TData1, TError1, any, any>,\n resultB: UseMutationResult<TData2, TError2, any, any>,\n): CombinedMutationResult<TData1 | TData2, TError1 | TError2> {\n {\n return {\n isPending: resultA.isPending || resultB.isPending,\n isSuccess: resultA.isSuccess && resultB.isSuccess,\n isError: resultA.isError || resultB.isError,\n isIdle: resultA.isIdle && resultB.isIdle,\n isPaused: resultA.isPaused || resultB.isPaused,\n submittedAt: resultA.submittedAt || resultB.submittedAt,\n status:\n resultA.isPending || resultB.isPending\n ? \"pending\"\n : resultA.isError || resultB.isError\n ? \"error\"\n : resultA.isSuccess && resultB.isSuccess\n ? \"success\"\n : \"idle\",\n error: resultA.error ?? resultB.error,\n failureCount: resultA.failureCount + resultB.failureCount,\n failureReason: resultA.failureReason ?? resultB.failureReason,\n };\n }\n}\n\nexport type CombinedQueryResult<TData1, TData2, TError1, TError2> = Omit<\n UseQueryResult<TData1 | TData2, TError1 | TError2>,\n \"data\" | \"refetch\" | \"promise\"\n>;\nexport function combineQueryResults<TData1, TData2, TError1, TError2>(\n resultA: UseQueryResult<TData1, TError1>,\n resultB: UseQueryResult<TData2, TError2>,\n): CombinedQueryResult<void, void, TError1, TError2> {\n return {\n isPending: resultA.isPending || resultB.isPending,\n isSuccess: resultA.isSuccess && resultB.isSuccess,\n isError: resultA.isError || resultB.isError,\n isLoading: resultA.isLoading || resultB.isLoading,\n isFetched: resultA.isFetched && resultB.isFetched,\n isFetchedAfterMount:\n resultA.isFetchedAfterMount && resultB.isFetchedAfterMount,\n isInitialLoading: resultA.isInitialLoading || resultB.isInitialLoading,\n isPaused: resultA.isPaused || resultB.isPaused,\n isLoadingError: resultA.isLoadingError || resultB.isLoadingError,\n isRefetchError: resultA.isRefetchError || resultB.isRefetchError,\n isPlaceholderData: resultA.isPlaceholderData || resultB.isPlaceholderData,\n isStale: resultA.isStale || resultB.isStale,\n isRefetching: resultA.isRefetching || resultB.isRefetching,\n isFetching: resultA.isFetching || resultB.isFetching,\n status:\n resultA.isPending || resultB.isPending\n ? \"pending\"\n : resultA.isError || resultB.isError\n ? \"error\"\n : resultA.isSuccess && resultB.isSuccess\n ? \"success\"\n : \"pending\",\n error: resultA.error ?? resultB.error,\n failureCount: resultA.failureCount + resultB.failureCount,\n failureReason: resultA.failureReason ?? resultB.failureReason,\n errorUpdateCount: resultA.errorUpdateCount + resultB.errorUpdateCount,\n fetchStatus:\n resultA.isFetching || resultB.isFetching\n ? \"fetching\"\n : resultA.isPaused || resultB.isPaused\n ? \"paused\"\n : \"idle\",\n dataUpdatedAt: Math.max(resultA.dataUpdatedAt, resultB.dataUpdatedAt),\n errorUpdatedAt: Math.max(resultA.errorUpdatedAt, resultB.errorUpdatedAt),\n };\n}\n"]}
1
+ {"version":3,"file":"query-utils.js","sourceRoot":"","sources":["../../src/util/query-utils.ts"],"names":[],"mappings":";;AAoBA,wDAyBC;AAcD,kDAyCC;AAxFD;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,OAAqD,EACrD,OAAqD;IAErD,CAAC;QACC,OAAO;YACL,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;YACjD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;YACjD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO;YAC3C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM;YACxC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ;YAC9C,WAAW,EAAE,OAAO,CAAC,W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MutationResult<\n TData = unknown,\n TError = unknown,\n TVariables = unknown,\n TContext = unknown,\n> = Omit<\n UseMutationResult<TData, TError, TVariables, TContext>,\n \"mutate\" | \"mutateAsync\" | \"reset\" | \"data\" | \"variables\" | \"context\"\n>;\n\n/**\n * Combines two mutation results, showing the \"loading state\" of the two\n * mutations. For instance, if either mutation is pending, the combined\n * mutation result will be pending.\n * @param resultA - The first mutation result\n * @param resultB - The second mutation result\n * @returns The combined mutation result\n */\nexport function combineMutationResults<TData1, TData2, TError1, TError2>(\n resultA: UseMutationResult<TData1, TError1, any, any>,\n resultB: UseMutationResult<TData2, TError2, any, any>,\n): CombinedMutationResult<TData1 | TData2, TError1 | TError2> {\n {\n return {\n isPending: resultA.isPending || resultB.isPending,\n isSuccess: resultA.isSuccess && resultB.isSuccess,\n isError: resultA.isError || resultB.isError,\n isIdle: resultA.isIdle && resultB.isIdle,\n isPaused: resultA.isPaused || resultB.isPaused,\n submittedAt: resultA.submittedAt || resultB.submittedAt,\n status:\n resultA.isPending || resultB.isPending\n ? \"pending\"\n : resultA.isError || resultB.isError\n ? \"error\"\n : resultA.isSuccess && resultB.isSuccess\n ? \"success\"\n : \"idle\",\n error: resultA.error ?? resultB.error,\n failureCount: resultA.failureCount + resultB.failureCount,\n failureReason: resultA.failureReason ?? resultB.failureReason,\n };\n }\n}\n\nexport type CombinedQueryResult<TData1, TData2, TError1, TError2> = Omit<\n UseQueryResult<TData1 | TData2, TError1 | TError2>,\n \"data\" | \"refetch\" | \"promise\"\n>;\n/**\n * Combines two query results, showing the \"loading state\" of the two queries.\n * For instance, if either query is loading, the combined query result will be\n * loading.\n * @param resultA - The first query result\n * @param resultB - The second query result\n * @returns The combined query result\n */\nexport function combineQueryResults<TData1, TData2, TError1, TError2>(\n resultA: UseQueryResult<TData1, TError1>,\n resultB: UseQueryResult<TData2, TError2>,\n): CombinedQueryResult<void, void, TError1, TError2> {\n return {\n isPending: resultA.isPending || resultB.isPending,\n isSuccess: resultA.isSuccess && resultB.isSuccess,\n isError: resultA.isError || resultB.isError,\n isLoading: resultA.isLoading || resultB.isLoading,\n isFetched: resultA.isFetched && resultB.isFetched,\n isFetchedAfterMount:\n resultA.isFetchedAfterMount && resultB.isFetchedAfterMount,\n isInitialLoading: resultA.isInitialLoading || resultB.isInitialLoading,\n isPaused: resultA.isPaused || resultB.isPaused,\n isLoadingError: resultA.isLoadingError || resultB.isLoadingError,\n isRefetchError: resultA.isRefetchError || resultB.isRefetchError,\n isPlaceholderData: resultA.isPlaceholderData || resultB.isPlaceholderData,\n isStale: resultA.isStale || resultB.isStale,\n isRefetching: resultA.isRefetching || resultB.isRefetching,\n isFetching: resultA.isFetching || resultB.isFetching,\n status:\n resultA.isPending || resultB.isPending\n ? \"pending\"\n : resultA.isError || resultB.isError\n ? \"error\"\n : resultA.isSuccess && resultB.isSuccess\n ? \"success\"\n : \"pending\",\n error: resultA.error ?? resultB.error,\n failureCount: resultA.failureCount + resultB.failureCount,\n failureReason: resultA.failureReason ?? resultB.failureReason,\n errorUpdateCount: resultA.errorUpdateCount + resultB.errorUpdateCount,\n fetchStatus:\n resultA.isFetching || resultB.isFetching\n ? \"fetching\"\n : resultA.isPaused || resultB.isPaused\n ? \"paused\"\n : \"idle\",\n dataUpdatedAt: Math.max(resultA.dataUpdatedAt, resultB.dataUpdatedAt),\n errorUpdatedAt: Math.max(resultA.errorUpdatedAt, resultB.errorUpdatedAt),\n };\n}\n"]}
@@ -1,9 +1,35 @@
1
1
  import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import { ComponentContextToolMetadata, ComponentRegistry, RegisteredComponent, TamboTool, TamboToolAssociations, TamboToolRegistry } from "../model/component-metadata";
3
+ /**
4
+ * Get all the available components from the component registry
5
+ * @param componentRegistry - The component registry
6
+ * @param toolRegistry - The tool registry
7
+ * @param toolAssociations - The tool associations
8
+ * @returns The available components
9
+ */
3
10
  export declare const getAvailableComponents: (componentRegistry: ComponentRegistry, toolRegistry: TamboToolRegistry, toolAssociations: TamboToolAssociations) => TamboAI.AvailableComponent[];
11
+ /**
12
+ * Helper function to convert component props from Zod schema to JSON Schema
13
+ * @param component - The component to convert
14
+ * @returns The converted props
15
+ */
4
16
  export declare const convertPropsToJsonSchema: (component: RegisteredComponent) => any;
17
+ /**
18
+ * Get a component by name from the component registry
19
+ * @param componentName - The name of the component to get
20
+ * @param componentRegistry - The component registry
21
+ * @returns The component registration information
22
+ */
5
23
  export declare const getComponentFromRegistry: (componentName: string, componentRegistry: ComponentRegistry) => RegisteredComponent;
6
- export declare const getDefaultContextAdditions: () => string[];
24
+ /**
25
+ * Get the client context for the current thread, such as the current time in the user's timezone
26
+ * @returns a string of context additions that will be added to the prompt when the thread is advanced.
27
+ */
7
28
  export declare const getClientContext: () => string;
29
+ /**
30
+ * Map a Tambo tool to a context tool
31
+ * @param tool - The tool to map
32
+ * @returns The context tool
33
+ */
8
34
  export declare const mapTamboToolToContextTool: (tool: TamboTool) => ComponentContextToolMetadata;
9
35
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAEjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAGF,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,MAAM,EAMnD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,MAGnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAEjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAUF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAO,MAGnC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
@@ -3,8 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapTamboToolToContextTool = exports.getClientContext = exports.getDefaultContextAdditions = exports.getComponentFromRegistry = exports.convertPropsToJsonSchema = exports.getAvailableComponents = void 0;
6
+ exports.mapTamboToolToContextTool = exports.getClientContext = exports.getComponentFromRegistry = exports.convertPropsToJsonSchema = exports.getAvailableComponents = void 0;
7
7
  const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
+ /**
9
+ * Get all the available components from the component registry
10
+ * @param componentRegistry - The component registry
11
+ * @param toolRegistry - The tool registry
12
+ * @param toolAssociations - The tool associations
13
+ * @returns The available components
14
+ */
8
15
  const getAvailableComponents = (componentRegistry, toolRegistry, toolAssociations) => {
9
16
  const availableComponents = [];
10
17
  for (const [name, componentEntry] of Object.entries(componentRegistry)) {
@@ -27,7 +34,11 @@ const getAvailableComponents = (componentRegistry, toolRegistry, toolAssociation
27
34
  return availableComponents;
28
35
  };
29
36
  exports.getAvailableComponents = getAvailableComponents;
30
- // Helper function to convert component props from Zod schema to JSON Schema
37
+ /**
38
+ * Helper function to convert component props from Zod schema to JSON Schema
39
+ * @param component - The component to convert
40
+ * @returns The converted props
41
+ */
31
42
  const convertPropsToJsonSchema = (component) => {
32
43
  if (!component.props) {
33
44
  return component.props;
@@ -40,6 +51,12 @@ const convertPropsToJsonSchema = (component) => {
40
51
  return component.props;
41
52
  };
42
53
  exports.convertPropsToJsonSchema = convertPropsToJsonSchema;
54
+ /**
55
+ * Get a component by name from the component registry
56
+ * @param componentName - The name of the component to get
57
+ * @param componentRegistry - The component registry
58
+ * @returns The component registration information
59
+ */
43
60
  const getComponentFromRegistry = (componentName, componentRegistry) => {
44
61
  const componentEntry = componentRegistry[componentName];
45
62
  if (!componentEntry) {
@@ -55,12 +72,20 @@ const getDefaultContextAdditions = () => {
55
72
  `The current time in user's timezone (${utcOffset}) is: ${new Date().toLocaleString()}`,
56
73
  ];
57
74
  };
58
- exports.getDefaultContextAdditions = getDefaultContextAdditions;
75
+ /**
76
+ * Get the client context for the current thread, such as the current time in the user's timezone
77
+ * @returns a string of context additions that will be added to the prompt when the thread is advanced.
78
+ */
59
79
  const getClientContext = () => {
60
- const contextAdditions = (0, exports.getDefaultContextAdditions)();
80
+ const contextAdditions = getDefaultContextAdditions();
61
81
  return contextAdditions.join("\n");
62
82
  };
63
83
  exports.getClientContext = getClientContext;
84
+ /**
85
+ * Map a Tambo tool to a context tool
86
+ * @param tool - The tool to map
87
+ * @returns The context tool
88
+ */
64
89
  const mapTamboToolToContextTool = (tool) => {
65
90
  const parameters = getParametersFromZodFunction(tool.toolSchema);
66
91
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAiD;AAW1C,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzD,MAAM,YAAY,GAAG;YACnB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtC,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACpC,IAAI,CAAC,IAAI;oBAAE,OAAO,IAAI,CAAC;gBACvB,OAAO,IAAA,iCAAyB,EAAC,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC;SACH,CAAC,MAAM,CAAC,CAAC,IAAI,EAAwC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAExE,mBAAmB,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,WAAW,EAAE,cAAc,CAAC,WAAW;YACvC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AA3BW,QAAA,sBAAsB,0BA2BjC;AAEF,4EAA4E;AACrE,MAAM,wBAAwB,GAAG,CACtC,SAA8B,EACzB,EAAE;IACP,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,0F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OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n ParameterSpec,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\n\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = [\n ...associatedToolNames.map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n }),\n ].filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n// Helper function to convert component props from Zod schema to JSON Schema\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): any => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Zod schema (we can't directly check the type, so we check for _def)\n if (component.props._def && typeof component.props.parse === \"function\") {\n // Use two-step type assertion for safety\n return zodToJsonSchema(component.props as unknown as z.ZodTypeAny);\n }\n\n return component.props;\n};\n\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\nexport const getDefaultContextAdditions = (): string[] => {\n const utcOffsetHours = new Date().getTimezoneOffset() / 60;\n const utcOffset = `(UTC${utcOffsetHours > 0 ? \"+\" : \"\"}${utcOffsetHours})`;\n return [\n `The current time in user's timezone (${utcOffset}) is: ${new Date().toLocaleString()}`,\n ];\n};\n\nexport const getClientContext = (): string => {\n const contextAdditions = getDefaultContextAdditions();\n return contextAdditions.join(\"\\n\");\n};\n\nexport const mapTamboToolToContextTool = (\n tool: TamboTool,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromZodFunction(tool.toolSchema);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\nconst getParametersFromZodFunction = (\n schema: z.ZodFunction<any, any>,\n): ParameterSpec[] => {\n const parameters: z.ZodTuple = schema.parameters();\n return parameters.items.map((param, index): ParameterSpec => {\n const name = `param${index + 1}`;\n const type = getZodBaseType(param);\n const description = param.description ?? \"\";\n const isRequired = !param.isOptional();\n const schema = zodToJsonSchema(param);\n\n return {\n name,\n type,\n description,\n isRequired,\n schema,\n };\n });\n};\n\nconst getZodBaseType = (schema: z.ZodTypeAny): string => {\n const typeName = schema._def.typeName;\n switch (typeName) {\n case \"ZodString\":\n return \"string\";\n case \"ZodNumber\":\n return \"number\";\n case \"ZodBoolean\":\n return \"boolean\";\n case \"ZodArray\":\n return \"array\";\n case \"ZodEnum\":\n return \"enum\";\n case \"ZodDate\":\n return \"date\";\n case \"ZodObject\":\n return \"object\";\n default:\n console.warn(\"falling back to string for\", typeName);\n return \"string\";\n }\n};\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAiD;AAWjD;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM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C,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAiB,EAAE;QAC1D,MAAM,IAAI,GAAG,QAAQ,KAAK,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;QAC5C,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAC;QAEtC,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,WAAW;YACX,UAAU;YACV,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,MAAoB,EAAU,EAAE;IACtD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACtC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,SAAS,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,OAAO,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n ParameterSpec,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\n\n/**\n * Get all the available components from the component registry\n * @param componentRegistry - The component registry\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The available components\n */\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = [\n ...associatedToolNames.map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n }),\n ].filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n/**\n * Helper function to convert component props from Zod schema to JSON Schema\n * @param component - The component to convert\n * @returns The converted props\n */\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): any => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Zod schema (we can't directly check the type, so we check for _def)\n if (component.props._def && typeof component.props.parse === \"function\") {\n // Use two-step type assertion for safety\n return zodToJsonSchema(component.props as unknown as z.ZodTypeAny);\n }\n\n return component.props;\n};\n\n/**\n * Get a component by name from the component registry\n * @param componentName - The name of the component to get\n * @param componentRegistry - The component registry\n * @returns The component registration information\n */\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\nconst getDefaultContextAdditions = (): string[] => {\n const utcOffsetHours = new Date().getTimezoneOffset() / 60;\n const utcOffset = `(UTC${utcOffsetHours > 0 ? \"+\" : \"\"}${utcOffsetHours})`;\n return [\n `The current time in user's timezone (${utcOffset}) is: ${new Date().toLocaleString()}`,\n ];\n};\n\n/**\n * Get the client context for the current thread, such as the current time in the user's timezone\n * @returns a string of context additions that will be added to the prompt when the thread is advanced.\n */\nexport const getClientContext = (): string => {\n const contextAdditions = getDefaultContextAdditions();\n return contextAdditions.join(\"\\n\");\n};\n\n/**\n * Map a Tambo tool to a context tool\n * @param tool - The tool to map\n * @returns The context tool\n */\nexport const mapTamboToolToContextTool = (\n tool: TamboTool,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromZodFunction(tool.toolSchema);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\nconst getParametersFromZodFunction = (\n schema: z.ZodFunction<any, any>,\n): ParameterSpec[] => {\n const parameters: z.ZodTuple = schema.parameters();\n return parameters.items.map((param, index): ParameterSpec => {\n const name = `param${index + 1}`;\n const type = getZodBaseType(param);\n const description = param.description ?? \"\";\n const isRequired = !param.isOptional();\n const schema = zodToJsonSchema(param);\n\n return {\n name,\n type,\n description,\n isRequired,\n schema,\n };\n });\n};\n\nconst getZodBaseType = (schema: z.ZodTypeAny): string => {\n const typeName = schema._def.typeName;\n switch (typeName) {\n case \"ZodString\":\n return \"string\";\n case \"ZodNumber\":\n return \"number\";\n case \"ZodBoolean\":\n return \"boolean\";\n case \"ZodArray\":\n return \"array\";\n case \"ZodEnum\":\n return \"enum\";\n case \"ZodDate\":\n return \"date\";\n case \"ZodObject\":\n return \"object\";\n default:\n console.warn(\"falling back to string for\", typeName);\n return \"string\";\n }\n};\n"]}
@@ -1,4 +1,10 @@
1
1
  import TamboAI from "@tambo-ai/typescript-sdk";
2
2
  import { TamboToolRegistry } from "../model/component-metadata";
3
+ /**
4
+ * Process a message from the thread, invoking the appropriate tool and returning the result.
5
+ * @param message - The message to handle
6
+ * @param toolRegistry - The tool registry
7
+ * @returns The result of the tool call
8
+ */
3
9
  export declare const handleToolCall: (message: TamboAI.Beta.ThreadMessage, toolRegistry: TamboToolRegistry) => Promise<any>;
4
10
  //# sourceMappingURL=tool-caller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-caller.d.ts","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAEL,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,cAAc,GACzB,SAAS,OAAO,CAAC,IAAI,CAAC,aAAa,EACnC,cAAc,iBAAiB,iBAUhC,CAAC"}
1
+ {"version":3,"file":"tool-caller.d.ts","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAEL,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAGrC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,OAAO,CAAC,IAAI,CAAC,aAAa,EACnC,cAAc,iBAAiB,iBAUhC,CAAC"}
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleToolCall = void 0;
4
4
  const registry_1 = require("./registry");
5
+ /**
6
+ * Process a message from the thread, invoking the appropriate tool and returning the result.
7
+ * @param message - The message to handle
8
+ * @param toolRegistry - The tool registry
9
+ * @returns The result of the tool call
10
+ */
5
11
  const handleToolCall = async (message, toolRegistry) => {
6
12
  if (!message?.toolCallRequest?.toolName) {
7
13
  throw new Error("Tool name is required");
@@ -1 +1 @@
1
- {"version":3,"file":"tool-caller.js","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":";;;AAKA,yCAAuD;AAChD,MAAM,cAAc,GAAG,KAAK,EACjC,OAAmC,EACnC,YAA+B,EAC/B,EAAE;IACF,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAEtE,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB;AAEF,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,YAA+B,EAAE,EAAE;IACrE,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,oCAAyB,EAAC,YAAY,CAAC,CAAC;IAC5D,OAAO;QACL,mBAAmB,EAAE,YAAY,CAAC,IAAI;QACtC,UAAU,EAAE,WAAW;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,KAAK,EACzB,eAAwC,EACxC,IAA0B,EACZ,EAAE;IAChB,mEAAmE;IACnE,MAAM,eAAe,GACnB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAEzE,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,eAAe,CAAC,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport {\n ComponentContextTool,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\nimport { mapTamboToolToContextTool } from \"./registry\";\nexport const handleToolCall = async (\n message: TamboAI.Beta.ThreadMessage,\n toolRegistry: TamboToolRegistry,\n) => {\n if (!message?.toolCallRequest?.toolName) {\n throw new Error(\"Tool name is required\");\n }\n\n const tool = findTool(message.toolCallRequest.toolName, toolRegistry);\n const toolResult = await runToolChoice(message.toolCallRequest, tool);\n\n return toolResult;\n};\n\nconst findTool = (toolName: string, toolRegistry: TamboToolRegistry) => {\n const registryTool = toolRegistry[toolName];\n\n if (!registryTool) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n\n const contextTool = mapTamboToolToContextTool(registryTool);\n return {\n getComponentContext: registryTool.tool,\n definition: contextTool,\n };\n};\n\nconst runToolChoice = async (\n toolCallRequest: TamboAI.ToolCallRequest,\n tool: ComponentContextTool,\n): Promise<any> => {\n // Assumes parameters are in the order they are defined in the tool\n const parameterValues =\n toolCallRequest.parameters?.map((param) => param.parameterValue) ?? [];\n\n return await tool.getComponentContext(...parameterValues);\n};\n"]}
1
+ {"version":3,"file":"tool-caller.js","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":";;;AAKA,yCAAuD;AAEvD;;;;;GAKG;AACI,MAAM,cAAc,GAAG,KAAK,EACjC,OAAmC,EACnC,YAA+B,EAC/B,EAAE;IACF,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAEtE,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB;AAEF,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,YAA+B,EAAE,EAAE;IACrE,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,oCAAyB,EAAC,YAAY,CAAC,CAAC;IAC5D,OAAO;QACL,mBAAmB,EAAE,YAAY,CAAC,IAAI;QACtC,UAAU,EAAE,WAAW;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,KAAK,EACzB,eAAwC,EACxC,IAA0B,EACZ,EAAE;IAChB,mEAAmE;IACnE,MAAM,eAAe,GACnB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAEzE,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,eAAe,CAAC,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport {\n ComponentContextTool,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\nimport { mapTamboToolToContextTool } from \"./registry\";\n\n/**\n * Process a message from the thread, invoking the appropriate tool and returning the result.\n * @param message - The message to handle\n * @param toolRegistry - The tool registry\n * @returns The result of the tool call\n */\nexport const handleToolCall = async (\n message: TamboAI.Beta.ThreadMessage,\n toolRegistry: TamboToolRegistry,\n) => {\n if (!message?.toolCallRequest?.toolName) {\n throw new Error(\"Tool name is required\");\n }\n\n const tool = findTool(message.toolCallRequest.toolName, toolRegistry);\n const toolResult = await runToolChoice(message.toolCallRequest, tool);\n\n return toolResult;\n};\n\nconst findTool = (toolName: string, toolRegistry: TamboToolRegistry) => {\n const registryTool = toolRegistry[toolName];\n\n if (!registryTool) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n\n const contextTool = mapTamboToolToContextTool(registryTool);\n return {\n getComponentContext: registryTool.tool,\n definition: contextTool,\n };\n};\n\nconst runToolChoice = async (\n toolCallRequest: TamboAI.ToolCallRequest,\n tool: ComponentContextTool,\n): Promise<any> => {\n // Assumes parameters are in the order they are defined in the tool\n const parameterValues =\n toolCallRequest.parameters?.map((param) => param.parameterValue) ?? [];\n\n return await tool.getComponentContext(...parameterValues);\n};\n"]}
@@ -3,12 +3,16 @@ import { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQu
3
3
  * Wrapper around useQuery that uses the internal tambo query client.
4
4
  *
5
5
  * Use this instead of useQuery from @tanstack/react-query
6
+ * @param options - The options for the query, same as useQuery from @tanstack/react-query
7
+ * @returns The query result
6
8
  */
7
9
  export declare function useTamboQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>): UseQueryResult<TData, TError>;
8
10
  /**
9
11
  * Wrapper around useMutation that uses the internal tambo query client.
10
12
  *
11
13
  * Use this instead of useMutation from @tanstack/react-query
14
+ * @param options - The options for the mutation, same as useMutation from @tanstack/react-query
15
+ * @returns The mutation result
12
16
  */
13
17
  export declare function useTamboMutation<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
14
18
  /**
@@ -17,6 +21,10 @@ export declare function useTamboMutation<TData = unknown, TError = Error, TVaria
17
21
  export type UseTamboMutationResult<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = UseMutationResult<TData, TError, TVariables, TContext>;
18
22
  /**
19
23
  * Hook for creating a mutation with the tambo query client.
24
+ *
25
+ * Use this instead of useMutation from @tanstack/react-query
26
+ * @param options - The options for the mutation, same as useMutation from @tanstack/react-query
27
+ * @returns The mutation result
20
28
  */
21
29
  export declare function useTamboMutationResult<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
22
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"react-query-hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,kBAAkB,EAClB,iBAAiB,EAE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MAAM,uBAAuB,CAAC;AAG/B;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,KAAK,EACd,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,OAAO,EAAE,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,iCAGjE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,0DAGjE;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAChC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,IAChB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,0DAEjE;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,IACZ,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC"}
@@ -5,6 +5,8 @@ import { useTamboQueryClient } from "../providers/tambo-client-provider";
5
5
  * Wrapper around useQuery that uses the internal tambo query client.
6
6
  *
7
7
  * Use this instead of useQuery from @tanstack/react-query
8
+ * @param options - The options for the query, same as useQuery from @tanstack/react-query
9
+ * @returns The query result
8
10
  */
9
11
  export function useTamboQuery(options) {
10
12
  const queryClient = useTamboQueryClient();
@@ -14,6 +16,8 @@ export function useTamboQuery(options) {
14
16
  * Wrapper around useMutation that uses the internal tambo query client.
15
17
  *
16
18
  * Use this instead of useMutation from @tanstack/react-query
19
+ * @param options - The options for the mutation, same as useMutation from @tanstack/react-query
20
+ * @returns The mutation result
17
21
  */
18
22
  export function useTamboMutation(options) {
19
23
  const queryClient = useTamboQueryClient();
@@ -21,6 +25,10 @@ export function useTamboMutation(options) {
21
25
  }
22
26
  /**
23
27
  * Hook for creating a mutation with the tambo query client.
28
+ *
29
+ * Use this instead of useMutation from @tanstack/react-query
30
+ * @param options - The options for the mutation, same as useMutation from @tanstack/react-query
31
+ * @returns The mutation result
24
32
  */
25
33
  export function useTamboMutationResult(options) {
26
34
  return useTamboMutation(options);
@@ -1 +1 @@
1
- {"version":3,"file":"react-query-hooks.js","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAEL,WAAW,EAGX,QAAQ,GAGT,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAK3B,OAAgE;IAChE,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,OAAO,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAK9B,OAAgE;IAChE,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAYD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAKpC,OAAgE;IAChE,OAAO,gBAAgB,CAAsC,OAAO,CAAC,CAAC;AACxE,CAAC","sourcesContent":["// tamboHooks.ts\nimport {\n QueryKey,\n useMutation,\n UseMutationOptions,\n UseMutationResult,\n useQuery,\n UseQueryOptions,\n UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useTamboQueryClient } from \"../providers/tambo-client-provider\";\n\n/**\n * Wrapper around useQuery that uses the internal tambo query client.\n *\n * Use this instead of useQuery from @tanstack/react-query\n */\nexport function useTamboQuery<\n TQueryFnData = unknown,\n TError = Error,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>) {\n const queryClient = useTamboQueryClient();\n return useQuery(options, queryClient);\n}\n\n/**\n * Wrapper around useMutation that uses the internal tambo query client.\n *\n * Use this instead of useMutation from @tanstack/react-query\n */\nexport function useTamboMutation<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n const queryClient = useTamboQueryClient();\n return useMutation(options, queryClient);\n}\n\n/**\n * Type alias for the result of a mutation.\n */\nexport type UseTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n> = UseMutationResult<TData, TError, TVariables, TContext>;\n\n/**\n * Hook for creating a mutation with the tambo query client.\n */\nexport function useTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n return useTamboMutation<TData, TError, TVariables, TContext>(options);\n}\n\n/**\n * Type alias for the result of a query.\n */\nexport type UseTamboQueryResult<\n TData = unknown,\n TError = Error,\n> = UseQueryResult<TData, TError>;\n"]}
1
+ {"version":3,"file":"react-query-hooks.js","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAEL,WAAW,EAGX,QAAQ,GAGT,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAK3B,OAAgE;IAChE,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,OAAO,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAK9B,OAAgE;IAChE,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAYD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAKpC,OAAgE;IAChE,OAAO,gBAAgB,CAAsC,OAAO,CAAC,CAAC;AACxE,CAAC","sourcesContent":["// tamboHooks.ts\nimport {\n QueryKey,\n useMutation,\n UseMutationOptions,\n UseMutationResult,\n useQuery,\n UseQueryOptions,\n UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useTamboQueryClient } from \"../providers/tambo-client-provider\";\n\n/**\n * Wrapper around useQuery that uses the internal tambo query client.\n *\n * Use this instead of useQuery from @tanstack/react-query\n * @param options - The options for the query, same as useQuery from @tanstack/react-query\n * @returns The query result\n */\nexport function useTamboQuery<\n TQueryFnData = unknown,\n TError = Error,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>) {\n const queryClient = useTamboQueryClient();\n return useQuery(options, queryClient);\n}\n\n/**\n * Wrapper around useMutation that uses the internal tambo query client.\n *\n * Use this instead of useMutation from @tanstack/react-query\n * @param options - The options for the mutation, same as useMutation from @tanstack/react-query\n * @returns The mutation result\n */\nexport function useTamboMutation<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n const queryClient = useTamboQueryClient();\n return useMutation(options, queryClient);\n}\n\n/**\n * Type alias for the result of a mutation.\n */\nexport type UseTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n> = UseMutationResult<TData, TError, TVariables, TContext>;\n\n/**\n * Hook for creating a mutation with the tambo query client.\n *\n * Use this instead of useMutation from @tanstack/react-query\n * @param options - The options for the mutation, same as useMutation from @tanstack/react-query\n * @returns The mutation result\n */\nexport function useTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n return useTamboMutation<TData, TError, TVariables, TContext>(options);\n}\n\n/**\n * Type alias for the result of a query.\n */\nexport type UseTamboQueryResult<\n TData = unknown,\n TError = Error,\n> = UseQueryResult<TData, TError>;\n"]}
@@ -9,16 +9,13 @@ type StateUpdateResult<T> = [
9
9
  /**
10
10
  * A React hook that provides state management and passes user updates to Tambo.
11
11
  * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.
12
- *
13
12
  * @param keyName - The unique key to identify this state within the message's componentState object
14
13
  * @param initialValue - Optional initial value for the state, used if no value exists in the message
15
14
  * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls
16
- *
17
15
  * @returns A tuple containing:
18
16
  * - The current state value
19
17
  * - A setter function to update the state (updates UI immediately, debounces server sync)
20
18
  * - A metadata object with properties like isPending to track sync status
21
- *
22
19
  * @example
23
20
  * // Basic usage
24
21
  * const [count, setCount, { isPending }] = useTamboComponentState("counter", 0);
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,9 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
+ import isEqual from "react-fast-compare";
2
3
  import { useDebouncedCallback } from "use-debounce";
3
4
  import { useTamboClient, useTamboThread } from "../providers";
4
5
  import { useTamboCurrentMessage, useTamboMessageContext, } from "./use-current-message";
6
+ // eslint-disable-next-line jsdoc/require-jsdoc
5
7
  export function useTamboComponentState(keyName, initialValue, debounceTime = 300) {
6
8
  const { threadId, messageId } = useTamboMessageContext();
7
9
  const { updateThreadMessage } = useTamboThread();
@@ -21,29 +23,6 @@ export function useTamboComponentState(keyName, initialValue, debounceTime = 300
21
23
  message &&
22
24
  cachedInitialValue !== undefined &&
23
25
  (!message.componentState || !(keyName in message.componentState));
24
- // Helper function to check if two values are deeply equal
25
- const isEqual = (a, b) => {
26
- if (a === b)
27
- return true;
28
- // Handle primitive types
29
- if (typeof a !== "object" ||
30
- typeof b !== "object" ||
31
- a === null ||
32
- b === null)
33
- return false;
34
- // For objects and arrays, do a shallow comparison for simplicity
35
- // This could be enhanced with a proper deep equality check if needed
36
- if (Array.isArray(a) && Array.isArray(b)) {
37
- if (a.length !== b.length)
38
- return false;
39
- return a.every((val, idx) => val === b[idx]);
40
- }
41
- const keysA = Object.keys(a);
42
- const keysB = Object.keys(b);
43
- if (keysA.length !== keysB.length)
44
- return false;
45
- return keysA.every((key) => a[key] === b[key]);
46
- };
47
26
  // Sync local state with message state on initial load and when message changes
48
27
  useEffect(() => {
49
28
  if (message?.componentState && keyName in message.componentState) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAwD/B,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACzD,MAAM,EAAE,mBAAmB,EAAE,GAAG,cAAc,EAAE,CAAC;IACjD,MAAM,MAAM,GAAG,cA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B,CAAC,QAAQ,CAAC,CAAC;QAC3B,aAAa,CAAC,QAAQ,CAAC,CAAC;QAExB,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;YACF,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EACD,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAC7C,CAAC;IAEF,gDAAgD;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n *\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n *\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n *\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\n\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 300,\n): StateUpdateResult<S> {\n const { threadId, messageId } = useTamboMessageContext();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Helper function to check if two values are deeply equal\n const isEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n\n // Handle primitive types\n if (\n typeof a !== \"object\" ||\n typeof b !== \"object\" ||\n a === null ||\n b === null\n )\n return false;\n\n // For objects and arrays, do a shallow comparison for simplicity\n // This could be enhanced with a proper deep equality check if needed\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((val, idx) => val === b[idx]);\n }\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n return keysA.every((key) => a[key] === b[key]);\n };\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // If this is a user-initiated state that matches what we're getting from server,\n // we can clear the lastUserValue flag since it's been synchronized\n if (lastUserValue !== null && isEqual(messageState, lastUserValue)) {\n setLastUserValue(null);\n }\n\n // Update local state with server state unless user has specifically changed this value\n // This allows streaming updates to continue while protecting user edits\n if (lastUserValue === null || !isEqual(localState, lastUserValue)) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one\n else if (cachedInitialValue !== undefined && !localState) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedSave = useDebouncedCallback(async (newValue: S) => {\n if (!message) {\n console.warn(\n `Cannot update missing message ${messageId} for state key \"${keyName}\"`,\n );\n setLastUserValue(null);\n return;\n }\n\n setIsPending(true);\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n\n // Only clear the lastUserValue when we've successfully synced this exact value\n if (isEqual(newValue, lastUserValue)) {\n setLastUserValue(null);\n }\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedSave(newValue);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n setLastUserValue(null);\n }\n },\n [debouncedSave, message, messageId, keyName],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedSave.flush();\n setLastUserValue(null);\n };\n }, [debouncedSave]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
1
+ {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAmD/B,+CAA+C;AAC/C,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YA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OAAO;QACP,OAAO;QACP,SAAS;QACT,QAAQ;QACR,mBAAmB;KACpB,CAAC,CAAC;IAEH,2CAA2C;IAC3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,gBAAgB,EAAE,CAAC;YACrB,eAAe,EAAE,CAAC;YAClB,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAExC,uCAAuC;IACvC,sEAAsE;IACtE,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,QAAW,EAAE,EAAE;QACd,wCAAwC;QACxC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3B,aAAa,CAAC,QAAQ,CAAC,CAAC;QAExB,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;YACF,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EACD,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAC7C,CAAC;IAEF,gDAAgD;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport isEqual from \"react-fast-compare\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 300,\n): StateUpdateResult<S> {\n const { threadId, messageId } = useTamboMessageContext();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // If this is a user-initiated state that matches what we're getting from server,\n // we can clear the lastUserValue flag since it's been synchronized\n if (lastUserValue !== null && isEqual(messageState, lastUserValue)) {\n setLastUserValue(null);\n }\n\n // Update local state with server state unless user has specifically changed this value\n // This allows streaming updates to continue while protecting user edits\n if (lastUserValue === null || !isEqual(localState, lastUserValue)) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one\n else if (cachedInitialValue !== undefined && !localState) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedSave = useDebouncedCallback(async (newValue: S) => {\n if (!message) {\n console.warn(\n `Cannot update missing message ${messageId} for state key \"${keyName}\"`,\n );\n setLastUserValue(null);\n return;\n }\n\n setIsPending(true);\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n\n // Only clear the lastUserValue when we've successfully synced this exact value\n if (isEqual(newValue, lastUserValue)) {\n setLastUserValue(null);\n }\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedSave(newValue);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n setLastUserValue(null);\n }\n },\n [debouncedSave, message, messageId, keyName],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedSave.flush();\n setLastUserValue(null);\n };\n }, [debouncedSave]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
@@ -1,19 +1,39 @@
1
1
  import React, { PropsWithChildren } from "react";
2
- /** Wraps all components, so that they can find what thread and message they are in */
2
+ /**
3
+ * Wraps all components, so that they can find what thread and message they are in
4
+ * @param props - props for the TamboMessageProvider
5
+ * @param props.children - The children to wrap
6
+ * @param props.threadId - The threadId of the thread
7
+ * @param props.messageId - The messageId of the message
8
+ * @returns The wrapped component
9
+ */
3
10
  export declare const TamboMessageProvider: React.FC<PropsWithChildren<{
4
11
  threadId: string;
5
12
  messageId: string;
6
13
  }>>;
7
- /** Wraps a component with a ComponentMessageProvider - this allows the provider
8
- * to be used outside of a TSX file */
14
+ /**
15
+ * Wraps a component with a ComponentMessageProvider - this allows the provider
16
+ * to be used outside of a TSX file
17
+ * @param children - The children to wrap
18
+ * @param threadId - The threadId of the thread
19
+ * @param messageId - The messageId of the message
20
+ * @returns The wrapped component
21
+ */
9
22
  export declare function wrapWithTamboMessageProvider(children: React.ReactNode, threadId: string, messageId: string): React.JSX.Element;
10
- /** Hook used inside a component wrapped with ComponentMessageProvider, to get
11
- * the threadId and messageId */
23
+ /**
24
+ * Hook used inside a component wrapped with ComponentMessageProvider, to get
25
+ * the threadId and messageId
26
+ * @returns The threadId and messageId
27
+ */
12
28
  export declare const useTamboMessageContext: () => {
13
29
  threadId: string;
14
30
  messageId: string;
15
31
  };
16
- /** Hook used inside a component wrapped with ComponentMessageProvider, to get
17
- * the current message */
32
+ /**
33
+ * Hook used inside a component wrapped with ComponentMessageProvider, to get
34
+ * the current message. The current thread will be fetched from the server, if
35
+ * it is not already in the cache.
36
+ * @returns The current message that is used to render the component
37
+ */
18
38
  export declare const useTamboCurrentMessage: () => import("..").TamboThreadMessage | undefined;
19
39
  //# sourceMappingURL=use-current-message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAQ5E,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3D,CAAC;AAEF;sCACsC;AACtC,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;gCACgC;AAEhC,eAAO,MAAM,sBAAsB;cArCvB,MAAM;eACL,MAAM;CA4ClB,CAAC;AAEF;yBACyB;AACzB,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
1
+ {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAQ5E;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;cApDvB,MAAM;eACL,MAAM;CA2DlB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
@@ -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"],"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,sFAAsF;AACtF,MAAM,CAAC,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACxC,gFAAgF;IAChF,2EAA2E;IAC3E,6EA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":["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,m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,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,QAwB3B"}