@tambo-ai/react 0.20.2 → 0.20.3

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 (75) hide show
  1. package/dist/hooks/__tests__/use-suggestions.test.js +66 -23
  2. package/dist/hooks/__tests__/use-suggestions.test.js.map +1 -1
  3. package/dist/hooks/__tests__/use-tambo-threads.test.d.ts +2 -0
  4. package/dist/hooks/__tests__/use-tambo-threads.test.d.ts.map +1 -0
  5. package/dist/hooks/__tests__/use-tambo-threads.test.js +212 -0
  6. package/dist/hooks/__tests__/use-tambo-threads.test.js.map +1 -0
  7. package/dist/hooks/react-query-hooks.d.ts +0 -8
  8. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  9. package/dist/hooks/react-query-hooks.js +0 -11
  10. package/dist/hooks/react-query-hooks.js.map +1 -1
  11. package/dist/hooks/use-suggestions.js +2 -2
  12. package/dist/hooks/use-suggestions.js.map +1 -1
  13. package/dist/hooks/use-tambo-threads.d.ts +13 -11
  14. package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
  15. package/dist/hooks/use-tambo-threads.js +3 -1
  16. package/dist/hooks/use-tambo-threads.js.map +1 -1
  17. package/dist/providers/__tests__/tambo-thread-provider.test.d.ts +2 -0
  18. package/dist/providers/__tests__/tambo-thread-provider.test.d.ts.map +1 -0
  19. package/dist/providers/__tests__/tambo-thread-provider.test.js +279 -0
  20. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -0
  21. package/dist/providers/tambo-provider.d.ts +1 -2
  22. package/dist/providers/tambo-provider.d.ts.map +1 -1
  23. package/dist/providers/tambo-provider.js.map +1 -1
  24. package/dist/providers/tambo-registry-provider.js +1 -4
  25. package/dist/providers/tambo-registry-provider.js.map +1 -1
  26. package/dist/setupTests.d.ts +3 -0
  27. package/dist/setupTests.d.ts.map +1 -0
  28. package/dist/setupTests.js +8 -0
  29. package/dist/setupTests.js.map +1 -0
  30. package/dist/testing/tools.d.ts +24 -0
  31. package/dist/testing/tools.d.ts.map +1 -0
  32. package/dist/testing/tools.js +31 -0
  33. package/dist/testing/tools.js.map +1 -0
  34. package/dist/testing/types.d.ts +4 -0
  35. package/dist/testing/types.d.ts.map +1 -0
  36. package/dist/testing/types.js +3 -0
  37. package/dist/testing/types.js.map +1 -0
  38. package/esm/hooks/__tests__/use-suggestions.test.js +69 -26
  39. package/esm/hooks/__tests__/use-suggestions.test.js.map +1 -1
  40. package/esm/hooks/__tests__/use-tambo-threads.test.d.ts +2 -0
  41. package/esm/hooks/__tests__/use-tambo-threads.test.d.ts.map +1 -0
  42. package/esm/hooks/__tests__/use-tambo-threads.test.js +210 -0
  43. package/esm/hooks/__tests__/use-tambo-threads.test.js.map +1 -0
  44. package/esm/hooks/react-query-hooks.d.ts +0 -8
  45. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  46. package/esm/hooks/react-query-hooks.js +0 -10
  47. package/esm/hooks/react-query-hooks.js.map +1 -1
  48. package/esm/hooks/use-suggestions.js +3 -3
  49. package/esm/hooks/use-suggestions.js.map +1 -1
  50. package/esm/hooks/use-tambo-threads.d.ts +13 -11
  51. package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
  52. package/esm/hooks/use-tambo-threads.js +3 -1
  53. package/esm/hooks/use-tambo-threads.js.map +1 -1
  54. package/esm/providers/__tests__/tambo-thread-provider.test.d.ts +2 -0
  55. package/esm/providers/__tests__/tambo-thread-provider.test.d.ts.map +1 -0
  56. package/esm/providers/__tests__/tambo-thread-provider.test.js +274 -0
  57. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -0
  58. package/esm/providers/tambo-provider.d.ts +1 -2
  59. package/esm/providers/tambo-provider.d.ts.map +1 -1
  60. package/esm/providers/tambo-provider.js.map +1 -1
  61. package/esm/providers/tambo-registry-provider.js +1 -4
  62. package/esm/providers/tambo-registry-provider.js.map +1 -1
  63. package/esm/setupTests.d.ts +3 -0
  64. package/esm/setupTests.d.ts.map +1 -0
  65. package/esm/setupTests.js +6 -0
  66. package/esm/setupTests.js.map +1 -0
  67. package/esm/testing/tools.d.ts +24 -0
  68. package/esm/testing/tools.d.ts.map +1 -0
  69. package/esm/testing/tools.js +25 -0
  70. package/esm/testing/tools.js.map +1 -0
  71. package/esm/testing/types.d.ts +4 -0
  72. package/esm/testing/types.d.ts.map +1 -0
  73. package/esm/testing/types.js +2 -0
  74. package/esm/testing/types.js.map +1 -0
  75. package/package.json +8 -6
@@ -1 +1 @@
1
- {"version":3,"file":"use-suggestions.js","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAEL,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAGL,sBAAsB,EACtB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAoD/E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,EAAE,CAAC;IACzC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,EAAE,aAAa,EAAE,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D,MAAM,CAAC,EAAE,EACT,eAAe,EACf;gBACE,cAAc;gBACd,6DAA6D;gBAC7D,mBAAmB,EAAE,CAAC,UAAU,CAAC;aAClC,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC,CAAC;QACJ,CAAC;QACD,yBAAyB;QACzB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,mEAAmE;IACnE,8DAA8D;IAC9D,MAAM,WAAW,GAAG,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
+ {"version":3,"file":"use-suggestions.js","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAEL,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAGL,gBAAgB,EAChB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAoD/E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,EAAE,CAAC;IACzC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAA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AW,CAAC,QAAQ,CACxD,MAAM,CAAC,EAAE,EACT,eAAe,EACf;gBACE,cAAc;gBACd,6DAA6D;gBAC7D,mBAAmB,EAAE,CAAC,UAAU,CAAC;aAClC,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC,CAAC;QACJ,CAAC;QACD,yBAAyB;QACzB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,mEAAmE;IACnE,8DAA8D;IAC9D,MAAM,WAAW,GAAG,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 useTamboMutation,\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 = useTamboMutation<\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 = useTamboMutation<\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,3 +1,5 @@
1
+ import type TamboAI from "@tambo-ai/typescript-sdk";
2
+ import { UseQueryOptions } from "@tanstack/react-query";
1
3
  interface UseTamboThreadListConfig {
2
4
  /**
3
5
  * The projectId to get the threads for. If not provided, the current project
@@ -33,7 +35,7 @@ interface UseTamboThreadListConfig {
33
35
  * @param config.contextKey - The context key to get the threads for
34
36
  * @returns The threads for the specified project and optional context key
35
37
  */
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> | {
38
+ export declare function useTamboThreadList({ projectId, contextKey }?: UseTamboThreadListConfig, options?: Partial<UseQueryOptions<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null>>): import("@tanstack/react-query").QueryObserverRefetchErrorResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverSuccessResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverLoadingErrorResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverPendingResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverPlaceholderResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | {
37
39
  error: Error;
38
40
  isError: true;
39
41
  isPending: false;
@@ -55,8 +57,8 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTambo
55
57
  isPaused: boolean;
56
58
  isRefetching: boolean;
57
59
  isStale: boolean;
58
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<string, Error>>;
59
- fetchStatus: import("@tanstack/query-core").FetchStatus;
60
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<string, Error>>;
61
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
60
62
  promise: Promise<string>;
61
63
  data: null;
62
64
  } | {
@@ -81,8 +83,8 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTambo
81
83
  isPaused: boolean;
82
84
  isRefetching: boolean;
83
85
  isStale: boolean;
84
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<string, Error>>;
85
- fetchStatus: import("@tanstack/query-core").FetchStatus;
86
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<string, Error>>;
87
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
86
88
  promise: Promise<string>;
87
89
  data: null;
88
90
  } | {
@@ -107,8 +109,8 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTambo
107
109
  isPaused: boolean;
108
110
  isRefetching: boolean;
109
111
  isStale: boolean;
110
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<string, Error>>;
111
- fetchStatus: import("@tanstack/query-core").FetchStatus;
112
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<string, Error>>;
113
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
112
114
  promise: Promise<string>;
113
115
  data: null;
114
116
  } | {
@@ -133,8 +135,8 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTambo
133
135
  isPaused: boolean;
134
136
  isRefetching: boolean;
135
137
  isStale: boolean;
136
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<string, Error>>;
137
- fetchStatus: import("@tanstack/query-core").FetchStatus;
138
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<string, Error>>;
139
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
138
140
  promise: Promise<string>;
139
141
  data: null;
140
142
  } | {
@@ -159,8 +161,8 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: UseTambo
159
161
  isPaused: boolean;
160
162
  isRefetching: boolean;
161
163
  isStale: boolean;
162
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<string, Error>>;
163
- fetchStatus: import("@tanstack/query-core").FetchStatus;
164
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<string, Error>>;
165
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
164
166
  promise: Promise<string>;
165
167
  data: null;
166
168
  };
@@ -1 +1 @@
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;IAC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+11,10 @@ import { useTamboQuery } from "./react-query-hooks";
11
11
  * @param config.contextKey - The context key to get the threads for
12
12
  * @returns The threads for the specified project and optional context key
13
13
  */
14
- export function useTamboThreadList({ projectId, contextKey, } = {}) {
14
+ export function useTamboThreadList({ projectId, contextKey } = {}, options = {}) {
15
15
  const client = useTamboClient();
16
16
  const { data: queriedProjectId, ...projectIdState } = useTamboQuery({
17
+ ...options,
17
18
  queryKey: ["projectId"],
18
19
  queryFn: async () => {
19
20
  return (await client.beta.projects.getCurrent()).id;
@@ -21,6 +22,7 @@ export function useTamboThreadList({ projectId, contextKey, } = {}) {
21
22
  });
22
23
  const currentProjectId = projectId ?? queriedProjectId;
23
24
  const threadState = useTamboQuery({
25
+ ...options,
24
26
  enabled: !!currentProjectId,
25
27
  queryKey: ["threads", currentProjectId, contextKey],
26
28
  queryFn: async () => {
@@ -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;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"]}
1
+ {"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA4BpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,EAAE,SAAS,EAAE,UAAU,KAA+B,EAAE,EACxD,UAEI,EAAE;IAEN,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa,CAAC;QAClE,GAAI,OAA8C;QAClD,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,GAAG,OAAO;QACV,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 type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { UseQueryOptions } from \"@tanstack/react-query\";\nimport { 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, contextKey }: UseTamboThreadListConfig = {},\n options: Partial<\n UseQueryOptions<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null>\n > = {},\n) {\n const client = useTamboClient();\n const { data: queriedProjectId, ...projectIdState } = useTamboQuery({\n ...(options as unknown as UseQueryOptions<string>),\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 ...options,\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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tambo-thread-provider.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-thread-provider.test.d.ts","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-thread-provider.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,274 @@
1
+ import { advanceStream } from "@tambo-ai/typescript-sdk";
2
+ import { act, renderHook } from "@testing-library/react";
3
+ import React from "react";
4
+ import { z } from "zod";
5
+ import { GenerationStage, } from "../../model/generate-component-response";
6
+ import { serializeRegistry } from "../../testing/tools";
7
+ import { useTamboClient } from "../tambo-client-provider";
8
+ import { TamboRegistryProvider } from "../tambo-registry-provider";
9
+ import { TamboThreadProvider, useTamboThread } from "../tambo-thread-provider";
10
+ // Mock crypto.randomUUID
11
+ Object.defineProperty(global, "crypto", {
12
+ value: {
13
+ randomUUID: jest.fn().mockReturnValue("test-uuid"),
14
+ },
15
+ });
16
+ // Mock the required providers
17
+ jest.mock("../tambo-client-provider", () => ({
18
+ useTamboClient: jest.fn(),
19
+ }));
20
+ jest.mock("@tambo-ai/typescript-sdk", () => ({
21
+ advanceStream: jest.fn(),
22
+ }));
23
+ // Test utilities
24
+ const createMockMessage = (overrides = {}) => ({
25
+ id: "test-message-1",
26
+ content: [{ type: "text", text: "Hello" }],
27
+ role: "user",
28
+ threadId: "test-thread-1",
29
+ createdAt: new Date().toISOString(),
30
+ componentState: {},
31
+ ...overrides,
32
+ });
33
+ const createMockThread = (overrides = {}) => ({
34
+ id: "test-thread-1",
35
+ messages: [],
36
+ createdAt: "2024-01-01T00:00:00Z",
37
+ projectId: "test-project",
38
+ updatedAt: "2024-01-01T00:00:00Z",
39
+ metadata: {},
40
+ ...overrides,
41
+ });
42
+ const createMockAdvanceResponse = (overrides = {}) => ({
43
+ responseMessageDto: {
44
+ id: "test-uuid",
45
+ content: [{ type: "text", text: "Default response" }],
46
+ role: "assistant",
47
+ threadId: "test-thread-1",
48
+ component: undefined,
49
+ componentState: {},
50
+ createdAt: new Date().toISOString(),
51
+ },
52
+ generationStage: GenerationStage.COMPLETE,
53
+ ...overrides,
54
+ });
55
+ describe("TamboThreadProvider", () => {
56
+ const mockThread = createMockThread();
57
+ const mockThreadsApi = {
58
+ messages: {
59
+ create: jest.fn(),
60
+ },
61
+ retrieve: jest.fn(),
62
+ advanceById: jest.fn(),
63
+ };
64
+ const mockBeta = {
65
+ threads: mockThreadsApi,
66
+ };
67
+ const mockTamboAI = {
68
+ apiKey: "",
69
+ components: {},
70
+ beta: mockBeta,
71
+ };
72
+ const mockRegistry = [
73
+ {
74
+ name: "TestOnly",
75
+ component: () => React.createElement("div", null, "TestOnly"),
76
+ description: "TestOnly",
77
+ propsSchema: z.object({
78
+ test: z.string(),
79
+ }),
80
+ associatedTools: [
81
+ {
82
+ name: "test-tool",
83
+ tool: jest.fn().mockResolvedValue("test-tool"),
84
+ description: "test-tool",
85
+ toolSchema: z
86
+ .function()
87
+ .args(z.string().describe("test-param-description"))
88
+ .returns(z.string()),
89
+ },
90
+ ],
91
+ },
92
+ ];
93
+ const wrapper = ({ children }) => (React.createElement(TamboRegistryProvider, { components: mockRegistry },
94
+ React.createElement(TamboThreadProvider, null, children)));
95
+ beforeEach(() => {
96
+ jest.mocked(mockThreadsApi.retrieve).mockResolvedValue(mockThread);
97
+ jest
98
+ .mocked(mockThreadsApi.messages.create)
99
+ .mockResolvedValue(createMockMessage());
100
+ jest
101
+ .mocked(mockThreadsApi.advanceById)
102
+ .mockResolvedValue(createMockAdvanceResponse());
103
+ jest.mocked(useTamboClient).mockReturnValue(mockTamboAI);
104
+ });
105
+ it("should initialize with placeholder thread", () => {
106
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
107
+ expect(result.current.thread.id).toBe("placeholder");
108
+ expect(result.current.isIdle).toBe(true);
109
+ expect(result.current.generationStage).toBe(GenerationStage.IDLE);
110
+ });
111
+ it("should switch to a new thread", async () => {
112
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
113
+ await act(async () => {
114
+ await result.current.switchCurrentThread("test-thread-1");
115
+ });
116
+ expect(mockThreadsApi.retrieve).toHaveBeenCalledWith("test-thread-1");
117
+ expect(result.current.thread.id).toBe("test-thread-1");
118
+ });
119
+ it("should start a new thread", async () => {
120
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
121
+ await act(async () => {
122
+ result.current.startNewThread();
123
+ });
124
+ expect(result.current.thread.id).toBe("placeholder");
125
+ expect(result.current.isIdle).toBe(true);
126
+ });
127
+ it("should add a message to the thread", async () => {
128
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
129
+ const testMessage = {
130
+ id: "test-message-1",
131
+ content: [{ type: "text", text: "Hello" }],
132
+ role: "user",
133
+ threadId: "test-thread-1",
134
+ createdAt: new Date().toISOString(),
135
+ componentState: {},
136
+ };
137
+ await act(async () => {
138
+ await result.current.addThreadMessage(testMessage, true);
139
+ });
140
+ expect(mockThreadsApi.messages.create).toHaveBeenCalledWith("test-thread-1", {
141
+ content: testMessage.content,
142
+ role: testMessage.role,
143
+ });
144
+ });
145
+ it("should update a message in the thread", async () => {
146
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
147
+ const testMessage = {
148
+ id: "test-message-1",
149
+ content: [{ type: "text", text: "Updated message" }],
150
+ role: "user",
151
+ threadId: "test-thread-1",
152
+ createdAt: new Date().toISOString(),
153
+ componentState: {},
154
+ };
155
+ await act(async () => {
156
+ await result.current.updateThreadMessage("test-message-1", testMessage, true);
157
+ });
158
+ expect(mockThreadsApi.messages.create).toHaveBeenCalledWith("test-thread-1", {
159
+ content: testMessage.content,
160
+ role: testMessage.role,
161
+ });
162
+ });
163
+ it("should send a message and update thread state", async () => {
164
+ const mockAdvanceResponse = {
165
+ responseMessageDto: {
166
+ id: "response-1",
167
+ content: [{ type: "text", text: "Response" }],
168
+ role: "assistant",
169
+ threadId: "test-thread-1",
170
+ component: undefined,
171
+ componentState: {},
172
+ createdAt: new Date().toISOString(),
173
+ },
174
+ generationStage: GenerationStage.COMPLETE,
175
+ };
176
+ jest
177
+ .mocked(mockThreadsApi.advanceById)
178
+ .mockResolvedValue(mockAdvanceResponse);
179
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
180
+ await act(async () => {
181
+ await result.current.sendThreadMessage("Hello", {
182
+ threadId: "test-thread-1",
183
+ streamResponse: false,
184
+ });
185
+ });
186
+ expect(mockThreadsApi.advanceById).toHaveBeenCalledWith("test-thread-1", {
187
+ messageToAppend: {
188
+ content: [{ type: "text", text: "Hello" }],
189
+ role: "user",
190
+ },
191
+ availableComponents: serializeRegistry(mockRegistry),
192
+ contextKey: undefined,
193
+ });
194
+ expect(result.current.generationStage).toBe(GenerationStage.COMPLETE);
195
+ });
196
+ it("should handle input value changes", () => {
197
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
198
+ act(() => {
199
+ result.current.setInputValue("New input");
200
+ });
201
+ expect(result.current.inputValue).toBe("New input");
202
+ });
203
+ it("should handle streaming responses", async () => {
204
+ const mockStreamResponse = {
205
+ responseMessageDto: {
206
+ id: "stream-1",
207
+ content: [{ type: "text", text: "Streaming response" }],
208
+ role: "assistant",
209
+ threadId: "test-thread-1",
210
+ component: undefined,
211
+ componentState: {},
212
+ createdAt: new Date().toISOString(),
213
+ },
214
+ generationStage: GenerationStage.COMPLETE,
215
+ };
216
+ // Create an async iterator mock
217
+ const mockAsyncIterator = {
218
+ [Symbol.asyncIterator]: async function* () {
219
+ yield mockStreamResponse;
220
+ },
221
+ };
222
+ // Mock advanceStream to return our async iterator
223
+ jest.mocked(advanceStream).mockResolvedValue(mockAsyncIterator);
224
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
225
+ await act(async () => {
226
+ await result.current.sendThreadMessage("Hello", {
227
+ threadId: "test-thread-1",
228
+ streamResponse: true,
229
+ });
230
+ });
231
+ expect(result.current.generationStage).toBe(GenerationStage.IDLE);
232
+ });
233
+ it("should handle tool calls during message processing", async () => {
234
+ const mockToolCallResponse = {
235
+ responseMessageDto: {
236
+ id: "tool-call-1",
237
+ content: [{ type: "text", text: "Tool response" }],
238
+ role: "tool",
239
+ threadId: "test-thread-1",
240
+ toolCallRequest: {
241
+ toolName: "test-tool",
242
+ parameters: [{ parameterName: "test", parameterValue: "test" }],
243
+ },
244
+ componentState: {},
245
+ createdAt: new Date().toISOString(),
246
+ },
247
+ generationStage: GenerationStage.COMPLETE,
248
+ };
249
+ jest
250
+ .mocked(mockThreadsApi.advanceById)
251
+ .mockResolvedValueOnce(mockToolCallResponse)
252
+ .mockResolvedValueOnce({
253
+ responseMessageDto: {
254
+ id: "advance-response2",
255
+ content: [{ type: "text", text: "response 2" }],
256
+ role: "user",
257
+ threadId: "test-thread-1",
258
+ componentState: {},
259
+ createdAt: new Date().toISOString(),
260
+ },
261
+ generationStage: GenerationStage.COMPLETE,
262
+ });
263
+ const { result } = renderHook(() => useTamboThread(), { wrapper });
264
+ await act(async () => {
265
+ await result.current.sendThreadMessage("Use tool", {
266
+ threadId: "test-thread-1",
267
+ streamResponse: false,
268
+ });
269
+ });
270
+ expect(result.current.generationStage).toBe(GenerationStage.COMPLETE);
271
+ expect(mockRegistry[0]?.associatedTools?.[0]?.tool).toHaveBeenCalledWith("test");
272
+ });
273
+ });
274
+ //# sourceMappingURL=tambo-thread-provider.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-thread-provider.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-thread-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,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AC,QAAQ;SAC1C,CAAC;QAEF,IAAI;aACD,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC;aAClC,qBAAqB,CAAC,oBAAoB,CAAC;aAC3C,qBAAqB,CAAC;YACrB,kBAAkB,EAAE;gBAClB,EAAE,EAAE,mBAAmB;gBACvB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;gBAC/C,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,eAAe;gBACzB,cAAc,EAAE,EAAE;gBAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC;YACD,eAAe,EAAE,eAAe,CAAC,QAAQ;SAC1C,CAAC,CAAC;QAEL,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAEnE,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,UAAU,EAAE;gBACjD,QAAQ,EAAE,eAAe;gBACzB,cAAc,EAAE,KAAK;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACtE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,oBAAoB,CACtE,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI, { advanceStream } from \"@tambo-ai/typescript-sdk\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport { DeepPartial } from \"ts-essentials\";\nimport { z } from \"zod\";\nimport { TamboComponent } from \"../../model/component-metadata\";\nimport {\n GenerationStage,\n TamboThreadMessage,\n} from \"../../model/generate-component-response\";\nimport { serializeRegistry } from \"../../testing/tools\";\nimport { useTamboClient } from \"../tambo-client-provider\";\nimport { TamboRegistryProvider } from \"../tambo-registry-provider\";\nimport { TamboThreadProvider, useTamboThread } from \"../tambo-thread-provider\";\n\ntype PartialTamboAI = DeepPartial<TamboAI>;\n\n// Mock crypto.randomUUID\nObject.defineProperty(global, \"crypto\", {\n value: {\n randomUUID: jest.fn().mockReturnValue(\"test-uuid\"),\n },\n});\n\n// Mock the required providers\njest.mock(\"../tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n}));\njest.mock(\"@tambo-ai/typescript-sdk\", () => ({\n advanceStream: jest.fn(),\n}));\n\n// Test utilities\nconst createMockMessage = (\n overrides: Partial<TamboThreadMessage> = {},\n): TamboThreadMessage => ({\n id: \"test-message-1\",\n content: [{ type: \"text\", text: \"Hello\" }],\n role: \"user\",\n threadId: \"test-thread-1\",\n createdAt: new Date().toISOString(),\n componentState: {},\n ...overrides,\n});\n\nconst createMockThread = (\n overrides: Partial<TamboAI.Beta.Threads.Thread> = {},\n) => ({\n id: \"test-thread-1\",\n messages: [],\n createdAt: \"2024-01-01T00:00:00Z\",\n projectId: \"test-project\",\n updatedAt: \"2024-01-01T00:00:00Z\",\n metadata: {},\n ...overrides,\n});\n\nconst createMockAdvanceResponse = (\n overrides: Partial<TamboAI.Beta.Threads.ThreadAdvanceResponse> = {},\n): TamboAI.Beta.Threads.ThreadAdvanceResponse => ({\n responseMessageDto: {\n id: \"test-uuid\",\n content: [{ type: \"text\" as const, text: \"Default response\" }],\n role: \"assistant\",\n threadId: \"test-thread-1\",\n component: undefined,\n componentState: {},\n createdAt: new Date().toISOString(),\n },\n generationStage: GenerationStage.COMPLETE,\n ...overrides,\n});\n\ndescribe(\"TamboThreadProvider\", () => {\n const mockThread = createMockThread();\n\n const mockThreadsApi = {\n messages: {\n create: jest.fn(),\n },\n retrieve: jest.fn(),\n advanceById: jest.fn(),\n } satisfies DeepPartial<\n TamboAI[\"beta\"][\"threads\"]\n > as unknown as TamboAI.Beta.Threads;\n\n const mockBeta = {\n threads: mockThreadsApi,\n } satisfies PartialTamboAI[\"beta\"];\n\n const mockTamboAI = {\n apiKey: \"\",\n components: {},\n beta: mockBeta,\n } satisfies PartialTamboAI as unknown as TamboAI;\n\n const mockRegistry: TamboComponent[] = [\n {\n name: \"TestOnly\",\n component: () => <div>TestOnly</div>,\n description: \"TestOnly\",\n propsSchema: z.object({\n test: z.string(),\n }),\n associatedTools: [\n {\n name: \"test-tool\",\n tool: jest.fn().mockResolvedValue(\"test-tool\"),\n description: \"test-tool\",\n toolSchema: z\n .function()\n .args(z.string().describe(\"test-param-description\"))\n .returns(z.string()),\n },\n ],\n },\n ];\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboRegistryProvider components={mockRegistry}>\n <TamboThreadProvider>{children}</TamboThreadProvider>\n </TamboRegistryProvider>\n );\n\n beforeEach(() => {\n jest.mocked(mockThreadsApi.retrieve).mockResolvedValue(mockThread);\n jest\n .mocked(mockThreadsApi.messages.create)\n .mockResolvedValue(createMockMessage());\n jest\n .mocked(mockThreadsApi.advanceById)\n .mockResolvedValue(createMockAdvanceResponse());\n jest.mocked(useTamboClient).mockReturnValue(mockTamboAI);\n });\n\n it(\"should initialize with placeholder thread\", () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n expect(result.current.thread.id).toBe(\"placeholder\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.generationStage).toBe(GenerationStage.IDLE);\n });\n\n it(\"should switch to a new thread\", async () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n await act(async () => {\n await result.current.switchCurrentThread(\"test-thread-1\");\n });\n\n expect(mockThreadsApi.retrieve).toHaveBeenCalledWith(\"test-thread-1\");\n expect(result.current.thread.id).toBe(\"test-thread-1\");\n });\n\n it(\"should start a new thread\", async () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n await act(async () => {\n result.current.startNewThread();\n });\n\n expect(result.current.thread.id).toBe(\"placeholder\");\n expect(result.current.isIdle).toBe(true);\n });\n\n it(\"should add a message to the thread\", async () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n const testMessage: TamboThreadMessage = {\n id: \"test-message-1\",\n content: [{ type: \"text\", text: \"Hello\" }],\n role: \"user\",\n threadId: \"test-thread-1\",\n createdAt: new Date().toISOString(),\n componentState: {},\n };\n\n await act(async () => {\n await result.current.addThreadMessage(testMessage, true);\n });\n\n expect(mockThreadsApi.messages.create).toHaveBeenCalledWith(\n \"test-thread-1\",\n {\n content: testMessage.content,\n role: testMessage.role,\n },\n );\n });\n\n it(\"should update a message in the thread\", async () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n const testMessage: TamboThreadMessage = {\n id: \"test-message-1\",\n content: [{ type: \"text\", text: \"Updated message\" }],\n role: \"user\",\n threadId: \"test-thread-1\",\n createdAt: new Date().toISOString(),\n componentState: {},\n };\n\n await act(async () => {\n await result.current.updateThreadMessage(\n \"test-message-1\",\n testMessage,\n true,\n );\n });\n\n expect(mockThreadsApi.messages.create).toHaveBeenCalledWith(\n \"test-thread-1\",\n {\n content: testMessage.content,\n role: testMessage.role,\n },\n );\n });\n\n it(\"should send a message and update thread state\", async () => {\n const mockAdvanceResponse: TamboAI.Beta.Threads.ThreadAdvanceResponse = {\n responseMessageDto: {\n id: \"response-1\",\n content: [{ type: \"text\", text: \"Response\" }],\n role: \"assistant\",\n threadId: \"test-thread-1\",\n component: undefined,\n componentState: {},\n createdAt: new Date().toISOString(),\n },\n generationStage: GenerationStage.COMPLETE,\n };\n\n jest\n .mocked(mockThreadsApi.advanceById)\n .mockResolvedValue(mockAdvanceResponse);\n\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n await act(async () => {\n await result.current.sendThreadMessage(\"Hello\", {\n threadId: \"test-thread-1\",\n streamResponse: false,\n });\n });\n\n expect(mockThreadsApi.advanceById).toHaveBeenCalledWith(\"test-thread-1\", {\n messageToAppend: {\n content: [{ type: \"text\", text: \"Hello\" }],\n role: \"user\",\n },\n availableComponents: serializeRegistry(mockRegistry),\n contextKey: undefined,\n });\n expect(result.current.generationStage).toBe(GenerationStage.COMPLETE);\n });\n\n it(\"should handle input value changes\", () => {\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n act(() => {\n result.current.setInputValue(\"New input\");\n });\n\n expect(result.current.inputValue).toBe(\"New input\");\n });\n\n it(\"should handle streaming responses\", async () => {\n const mockStreamResponse: TamboAI.Beta.Threads.ThreadAdvanceResponse = {\n responseMessageDto: {\n id: \"stream-1\",\n content: [{ type: \"text\", text: \"Streaming response\" }],\n role: \"assistant\",\n threadId: \"test-thread-1\",\n component: undefined,\n componentState: {},\n createdAt: new Date().toISOString(),\n },\n generationStage: GenerationStage.COMPLETE,\n };\n\n // Create an async iterator mock\n const mockAsyncIterator = {\n [Symbol.asyncIterator]: async function* () {\n yield mockStreamResponse;\n },\n };\n\n // Mock advanceStream to return our async iterator\n jest.mocked(advanceStream).mockResolvedValue(mockAsyncIterator);\n\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n await act(async () => {\n await result.current.sendThreadMessage(\"Hello\", {\n threadId: \"test-thread-1\",\n streamResponse: true,\n });\n });\n\n expect(result.current.generationStage).toBe(GenerationStage.IDLE);\n });\n\n it(\"should handle tool calls during message processing\", async () => {\n const mockToolCallResponse: TamboAI.Beta.Threads.ThreadAdvanceResponse = {\n responseMessageDto: {\n id: \"tool-call-1\",\n content: [{ type: \"text\", text: \"Tool response\" }],\n role: \"tool\",\n threadId: \"test-thread-1\",\n toolCallRequest: {\n toolName: \"test-tool\",\n parameters: [{ parameterName: \"test\", parameterValue: \"test\" }],\n },\n componentState: {},\n createdAt: new Date().toISOString(),\n },\n generationStage: GenerationStage.COMPLETE,\n };\n\n jest\n .mocked(mockThreadsApi.advanceById)\n .mockResolvedValueOnce(mockToolCallResponse)\n .mockResolvedValueOnce({\n responseMessageDto: {\n id: \"advance-response2\",\n content: [{ type: \"text\", text: \"response 2\" }],\n role: \"user\",\n threadId: \"test-thread-1\",\n componentState: {},\n createdAt: new Date().toISOString(),\n },\n generationStage: GenerationStage.COMPLETE,\n });\n\n const { result } = renderHook(() => useTamboThread(), { wrapper });\n\n await act(async () => {\n await result.current.sendThreadMessage(\"Use tool\", {\n threadId: \"test-thread-1\",\n streamResponse: false,\n });\n });\n expect(result.current.generationStage).toBe(GenerationStage.COMPLETE);\n expect(mockRegistry[0]?.associatedTools?.[0]?.tool).toHaveBeenCalledWith(\n \"test\",\n );\n });\n});\n"]}
@@ -15,7 +15,7 @@ import { TamboThreadContextProps } from "./tambo-thread-provider";
15
15
  * @returns The TamboProvider component
16
16
  */
17
17
  export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>>;
18
- type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboComponentContextProps;
18
+ export type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboComponentContextProps;
19
19
  export declare const TamboContext: React.Context<TamboContextProps>;
20
20
  /**
21
21
  * The useTambo hook provides access to the Tambo API. This is the primary entrypoint
@@ -25,5 +25,4 @@ export declare const TamboContext: React.Context<TamboContextProps>;
25
25
  * @returns The Tambo API
26
26
  */
27
27
  export declare const useTambo: () => TamboContextProps;
28
- export {};
29
28
  //# sourceMappingURL=tambo-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EAGxB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CAAC,wBAAwB,GAAG,0BAA0B,CAAC,CAsBzE,CAAC;AACF,KAAK,iBAAiB,GAAG,uBAAuB,GAC9C,uBAAuB,GACvB,0BAA0B,CAAC;AAE7B,eAAO,MAAM,YAAY,kCAExB,CAAC;AA6BF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
1
+ {"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EAGxB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CAAC,wBAAwB,GAAG,0BAA0B,CAAC,CAsBzE,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACrD,uBAAuB,GACvB,0BAA0B,CAAC;AAE7B,eAAO,MAAM,YAAY,kCAExB,CAAC;AA6BF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAEL,mBAAmB,EAEnB,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GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>\n> = ({ children, tamboUrl, apiKey, components, environment }) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components}>\n <TamboThreadProvider>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\ntype TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
1
+ {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAEtB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE;IAC9D,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CACL,oBAAC,mBAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW;QAExB,oBAAC,qBAAqB,IAAC,UAAU,EAAE,UAAU;YAC3C,oBAAC,mBAAmB;gBAClB,oBAAC,sBAAsB;oBACrB,oBAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAgC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;IAE9C,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>\n> = ({ children, tamboUrl, apiKey, components, environment }) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components}>\n <TamboThreadProvider>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import React, { createContext, useCallback, useContext, useEffect, useState, } from "react";
3
- import z, { ZodSchema } from "zod";
3
+ import { ZodSchema } from "zod";
4
4
  import zodToJsonSchema from "zod-to-json-schema";
5
5
  const TamboRegistryContext = createContext({
6
6
  componentList: {},
@@ -125,9 +125,6 @@ function getSerializedProps(propsDefinition, propsSchema, name) {
125
125
  console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);
126
126
  return propsDefinition;
127
127
  }
128
- if (propsSchema instanceof ZodSchema || propsSchema instanceof z.ZodObject) {
129
- return zodToJsonSchema(propsSchema);
130
- }
131
128
  if (isZodSchema(propsSchema)) {
132
129
  try {
133
130
  return zodToJsonSchema(propsSchema);