@tambo-ai/react 0.54.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +49 -14
  2. package/dist/hooks/__tests__/use-tambo-threads.test.js +1 -9
  3. package/dist/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  4. package/dist/mcp/__tests__/mcp-client.test.js +21 -21
  5. package/dist/mcp/__tests__/mcp-client.test.js.map +1 -1
  6. package/dist/mcp/__tests__/tambo-mcp-provider.test.js +115 -0
  7. package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  8. package/dist/mcp/mcp-client.d.ts +61 -210
  9. package/dist/mcp/mcp-client.d.ts.map +1 -1
  10. package/dist/mcp/mcp-client.js +43 -17
  11. package/dist/mcp/mcp-client.js.map +1 -1
  12. package/dist/mcp/tambo-mcp-provider.d.ts +1 -1
  13. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  14. package/dist/mcp/tambo-mcp-provider.js +22 -4
  15. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  16. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +15 -0
  17. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  18. package/dist/providers/__tests__/tambo-registry-provider.test.js +44 -9
  19. package/dist/providers/__tests__/tambo-registry-provider.test.js.map +1 -1
  20. package/dist/providers/hooks/use-tambo-session-token.d.ts +2 -2
  21. package/dist/providers/hooks/use-tambo-session-token.js +2 -2
  22. package/dist/providers/hooks/use-tambo-session-token.js.map +1 -1
  23. package/dist/providers/tambo-context-helpers-provider.d.ts +7 -2
  24. package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  25. package/dist/providers/tambo-context-helpers-provider.js +12 -7
  26. package/dist/providers/tambo-context-helpers-provider.js.map +1 -1
  27. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  28. package/dist/providers/tambo-interactable-provider.js +3 -0
  29. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  30. package/dist/providers/tambo-prop-stream-provider/index.d.ts +1 -1
  31. package/dist/providers/tambo-prop-stream-provider/index.js +1 -1
  32. package/dist/providers/tambo-prop-stream-provider/index.js.map +1 -1
  33. package/dist/providers/tambo-provider.d.ts +1 -1
  34. package/dist/providers/tambo-provider.js +1 -1
  35. package/dist/providers/tambo-provider.js.map +1 -1
  36. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  37. package/dist/providers/tambo-registry-provider.js +12 -1
  38. package/dist/providers/tambo-registry-provider.js.map +1 -1
  39. package/dist/util/validate-component-name.d.ts +7 -0
  40. package/dist/util/validate-component-name.d.ts.map +1 -0
  41. package/dist/util/validate-component-name.js +14 -0
  42. package/dist/util/validate-component-name.js.map +1 -0
  43. package/esm/hooks/__tests__/use-tambo-threads.test.js +1 -9
  44. package/esm/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  45. package/esm/mcp/__tests__/mcp-client.test.js +21 -21
  46. package/esm/mcp/__tests__/mcp-client.test.js.map +1 -1
  47. package/esm/mcp/__tests__/tambo-mcp-provider.test.js +83 -1
  48. package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  49. package/esm/mcp/mcp-client.d.ts +61 -210
  50. package/esm/mcp/mcp-client.d.ts.map +1 -1
  51. package/esm/mcp/mcp-client.js +43 -17
  52. package/esm/mcp/mcp-client.js.map +1 -1
  53. package/esm/mcp/tambo-mcp-provider.d.ts +1 -1
  54. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  55. package/esm/mcp/tambo-mcp-provider.js +22 -4
  56. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  57. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +15 -0
  58. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  59. package/esm/providers/__tests__/tambo-registry-provider.test.js +44 -9
  60. package/esm/providers/__tests__/tambo-registry-provider.test.js.map +1 -1
  61. package/esm/providers/hooks/use-tambo-session-token.d.ts +2 -2
  62. package/esm/providers/hooks/use-tambo-session-token.js +2 -2
  63. package/esm/providers/hooks/use-tambo-session-token.js.map +1 -1
  64. package/esm/providers/tambo-context-helpers-provider.d.ts +7 -2
  65. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  66. package/esm/providers/tambo-context-helpers-provider.js +12 -7
  67. package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
  68. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  69. package/esm/providers/tambo-interactable-provider.js +3 -0
  70. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  71. package/esm/providers/tambo-prop-stream-provider/index.d.ts +1 -1
  72. package/esm/providers/tambo-prop-stream-provider/index.js +1 -1
  73. package/esm/providers/tambo-prop-stream-provider/index.js.map +1 -1
  74. package/esm/providers/tambo-provider.d.ts +1 -1
  75. package/esm/providers/tambo-provider.js +1 -1
  76. package/esm/providers/tambo-provider.js.map +1 -1
  77. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  78. package/esm/providers/tambo-registry-provider.js +12 -1
  79. package/esm/providers/tambo-registry-provider.js.map +1 -1
  80. package/esm/util/validate-component-name.d.ts +7 -0
  81. package/esm/util/validate-component-name.d.ts.map +1 -0
  82. package/esm/util/validate-component-name.js +11 -0
  83. package/esm/util/validate-component-name.js.map +1 -0
  84. package/package.json +12 -11
@@ -1 +1 @@
1
- {"version":3,"file":"use-tambo-session-token.js","sourceRoot":"","sources":["../../../src/providers/hooks/use-tambo-session-token.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAe,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAe,EACf,WAAwB,EACxB,SAA6B;IAE7B,MAAM,MAAM,GAAG,QAAQ,CACrB;QACE,QAAQ,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC;QAC5C,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,YAAY,GAAG;gBACnB,UAAU,EAAE,iDAAiD;gBAC7D,qGAAqG;gBACrG,aAAa,EAAE,SAAU;gBACzB,kBAAkB,EAAE,+CAA+C;aACpE,CAAC;YACF,MAAM,uBAAuB,GAAG,IAAI,eAAe,CACjD,YAAY,CACb,CAAC,QAAQ,EAAE,CAAC;YACb,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CACjD,uBAAuB,CACxB,CAAC;YACF,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAyB,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,SAAS;QACpB,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE;YAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;gBAClC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YAC7C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,EACD,WAAW,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,YAAY,IAAI,IAAI,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC;IAC9B,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, useQuery } from \"@tanstack/react-query\";\nimport { useEffect } from \"react\";\n\n/**\n * This internal hook is used to get the Tambo session token and keep it\n * refreshed.\n *\n * It will refresh the token when it expires.\n * It will also set the bearer token on the client.\n *\n * This hook is used by the TamboClientProvider.\n * @param client - The Tambo client.\n * @param queryClient - The query client.\n * @param userToken - The user token.\n * @returns The Tambo session token.\n */\nexport function useTamboSessionToken(\n client: TamboAI,\n queryClient: QueryClient,\n userToken: string | undefined,\n) {\n const result = useQuery(\n {\n queryKey: [\"tambo-session-token\", userToken],\n queryFn: async () => {\n const tokenRequest = {\n grant_type: \"urn:ietf:params:oauth:grant-type:token-exchange\",\n // will only be undefined if the userToken is not provided, in which case the query will be disabled.\n subject_token: userToken!,\n subject_token_type: \"urn:ietf:params:oauth:token-type:access_token\",\n };\n const tokenRequestFormEncoded = new URLSearchParams(\n tokenRequest,\n ).toString();\n const tokenAsArrayBuffer = new TextEncoder().encode(\n tokenRequestFormEncoded,\n );\n return await client.beta.auth.getToken(tokenAsArrayBuffer as any);\n },\n enabled: !!userToken,\n refetchInterval: (result) => {\n if (result.state.data?.expires_in) {\n return result.state.data.expires_in * 1000;\n }\n return false;\n },\n },\n queryClient,\n );\n const accessToken = result.data?.access_token ?? null;\n useEffect(() => {\n client.bearer = accessToken;\n }, [accessToken, client]);\n return result;\n}\n"]}
1
+ {"version":3,"file":"use-tambo-session-token.js","sourceRoot":"","sources":["../../../src/providers/hooks/use-tambo-session-token.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAe,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAe,EACf,WAAwB,EACxB,SAA6B;IAE7B,MAAM,MAAM,GAAG,QAAQ,CACrB;QACE,QAAQ,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC;QAC5C,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,YAAY,GAAG;gBACnB,UAAU,EAAE,iDAAiD;gBAC7D,qGAAqG;gBACrG,aAAa,EAAE,SAAU;gBACzB,kBAAkB,EAAE,+CAA+C;aACpE,CAAC;YACF,MAAM,uBAAuB,GAAG,IAAI,eAAe,CACjD,YAAY,CACb,CAAC,QAAQ,EAAE,CAAC;YACb,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CACjD,uBAAuB,CACxB,CAAC;YACF,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAyB,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,SAAS;QACpB,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE;YAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;gBAClC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YAC7C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,EACD,WAAW,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,YAAY,IAAI,IAAI,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC;IAC9B,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, useQuery } from \"@tanstack/react-query\";\nimport { useEffect } from \"react\";\n\n/**\n * This internal hook is used to get the Tambo session token and keep it\n * refreshed.\n *\n * It will refresh the token when it expires.\n * It will also set the bearer token on the client.\n *\n * This hook is used by the TamboClientProvider.\n * @param client - The Tambo client.\n * @param queryClient - The query client.\n * @param userToken - The third-party OAuth token to exchange for a Tambo session.\n * @returns React Query result for the session token (token data, fetching state, errors).\n */\nexport function useTamboSessionToken(\n client: TamboAI,\n queryClient: QueryClient,\n userToken: string | undefined,\n) {\n const result = useQuery(\n {\n queryKey: [\"tambo-session-token\", userToken],\n queryFn: async () => {\n const tokenRequest = {\n grant_type: \"urn:ietf:params:oauth:grant-type:token-exchange\",\n // will only be undefined if the userToken is not provided, in which case the query will be disabled.\n subject_token: userToken!,\n subject_token_type: \"urn:ietf:params:oauth:token-type:access_token\",\n };\n const tokenRequestFormEncoded = new URLSearchParams(\n tokenRequest,\n ).toString();\n const tokenAsArrayBuffer = new TextEncoder().encode(\n tokenRequestFormEncoded,\n );\n return await client.beta.auth.getToken(tokenAsArrayBuffer as any);\n },\n enabled: !!userToken,\n refetchInterval: (result) => {\n if (result.state.data?.expires_in) {\n return result.state.data.expires_in * 1000;\n }\n return false;\n },\n },\n queryClient,\n );\n const accessToken = result.data?.access_token ?? null;\n useEffect(() => {\n client.bearer = accessToken;\n }, [accessToken, client]);\n return result;\n}\n"]}
@@ -30,8 +30,13 @@ export interface TamboContextHelpersContextProps {
30
30
  export declare const TamboContextHelpersProvider: React.FC<PropsWithChildren<TamboContextHelpersProviderProps>>;
31
31
  /**
32
32
  * Hook to access context helpers functionality.
33
- * Safe to call even when no provider is present: proxies to the global registry.
34
- * @returns The context helpers context props (registry-backed).
33
+ *
34
+ * Behavior without a provider: this hook does NOT throw immediately. If it is
35
+ * called outside of a `TamboContextHelpersProvider`, it returns a fallback
36
+ * object whose methods will throw when invoked. This "lazy-throw" pattern is
37
+ * intentional so the error surfaces at the actual point of use.
38
+ * @returns The context helpers API when a provider is present; otherwise, a
39
+ * fallback object whose methods throw if called.
35
40
  */
36
41
  export declare const useTamboContextHelpers: () => TamboContextHelpersContextProps;
37
42
  //# sourceMappingURL=tambo-context-helpers-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-helpers-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-context-helpers-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,gCAAgC;IAC/C;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,+BAA+B;IAC9C,iEAAiE;IACjE,oBAAoB,EAAE,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACzD,0CAA0C;IAC1C,iBAAiB,EAAE,MAAM,cAAc,CAAC;IACxC,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IAClE,sCAAsC;IACtC,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAKD;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,EAAE,KAAK,CAAC,EAAE,CAChD,iBAAiB,CAAC,gCAAgC,CAAC,CAkEpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,uCAmBlC,CAAC"}
1
+ {"version":3,"file":"tambo-context-helpers-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-context-helpers-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,gCAAgC;IAC/C;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,+BAA+B;IAC9C,iEAAiE;IACjE,oBAAoB,EAAE,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACzD,0CAA0C;IAC1C,iBAAiB,EAAE,MAAM,cAAc,CAAC;IACxC,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IAClE,sCAAsC;IACtC,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAKD;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,EAAE,KAAK,CAAC,EAAE,CAChD,iBAAiB,CAAC,gCAAgC,CAAC,CAkEpD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,uCA2BlC,CAAC"}
@@ -63,26 +63,31 @@ export const TamboContextHelpersProvider = ({ children, contextHelpers }) => {
63
63
  };
64
64
  /**
65
65
  * Hook to access context helpers functionality.
66
- * Safe to call even when no provider is present: proxies to the global registry.
67
- * @returns The context helpers context props (registry-backed).
66
+ *
67
+ * Behavior without a provider: this hook does NOT throw immediately. If it is
68
+ * called outside of a `TamboContextHelpersProvider`, it returns a fallback
69
+ * object whose methods will throw when invoked. This "lazy-throw" pattern is
70
+ * intentional so the error surfaces at the actual point of use.
71
+ * @returns The context helpers API when a provider is present; otherwise, a
72
+ * fallback object whose methods throw if called.
68
73
  */
69
74
  export const useTamboContextHelpers = () => {
70
75
  const context = useContext(TamboContextHelpersContext);
71
76
  if (context)
72
77
  return context;
73
- // Fallback to global registry so the API is standalone outside any provider
78
+ // No provider present: return methods that throw with a helpful error when used
74
79
  return {
75
80
  getAdditionalContext: async () => {
76
- throw new Error("No provider found");
81
+ throw new Error("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
77
82
  },
78
83
  getContextHelpers: () => {
79
- throw new Error("No provider found");
84
+ throw new Error("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
80
85
  },
81
86
  addContextHelper: (_name, _helper) => {
82
- throw new Error("No provider found");
87
+ throw new Error("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
83
88
  },
84
89
  removeContextHelper: (_name) => {
85
- throw new Error("No provider found");
90
+ throw new Error("useTamboContextHelpers must be used within a TamboContextHelpersProvider");
86
91
  },
87
92
  };
88
93
  };
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-helpers-provider.js","sourceRoot":"","sources":["../../src/providers/t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,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAE5B,4EAA4E;IAC5E,OAAO;QACL,oBAAoB,EAAE,KAAK,IAAI,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QACD,gBAAgB,EAAE,CAAC,KAAa,EAAE,OAAwB,EAAE,EAAE;YAC5D,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QACD,mBAAmB,EAAE,CAAC,KAAa,EAAE,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;KACiC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"../context-helpers\";\nimport { resolveAdditionalContext } from \"../context-helpers/registry\";\n\nexport interface TamboContextHelpersProviderProps {\n /**\n * A dictionary of context helper functions.\n * The key becomes the AdditionalContext.name and the function returns the value.\n * Return null/undefined to skip including that context.\n */\n contextHelpers?: ContextHelpers;\n}\n\nexport interface TamboContextHelpersContextProps {\n /** Get all additional context by running all helper functions */\n getAdditionalContext: () => Promise<AdditionalContext[]>;\n /** Get the current context helpers map */\n getContextHelpers: () => ContextHelpers;\n /** Add or update a context helper by name */\n addContextHelper: (name: string, helper: ContextHelperFn) => void;\n /** Remove a context helper by name */\n removeContextHelper: (name: string) => void;\n}\n\nconst TamboContextHelpersContext =\n createContext<TamboContextHelpersContextProps | null>(null);\n\n/**\n * Provider for managing additional context helpers.\n * Accepts a map of { key: () => any | null | undefined | Promise<any | null | undefined> }.\n * Returning null/undefined skips inclusion; returned values are wrapped as { name: key, context: value }.\n * @param props - The props for the TamboContextHelpersProvider.\n * @param props.contextHelpers - A dictionary of context helper functions keyed by context name.\n * @param props.children - The children to render.\n * @returns The provider that exposes context helper APIs via useTamboContextHelpers.\n */\nexport const TamboContextHelpersProvider: React.FC<\n PropsWithChildren<TamboContextHelpersProviderProps>\n> = ({ children, contextHelpers }) => {\n const [helpers, setHelpers] = useState<Record<string, ContextHelperFn>>({});\n const addContextHelper = useCallback((name: string, fn: ContextHelperFn) => {\n setHelpers((prev) => ({ ...prev, [name]: fn }));\n }, []);\n const removeContextHelper = useCallback(\n (name: string, fn?: ContextHelperFn) => {\n setHelpers((prev) => {\n const { [name]: registeredFn, ...rest } = prev;\n if (fn === undefined || registeredFn === fn) {\n return rest;\n }\n return prev;\n });\n },\n [],\n );\n // Hydrate the global registry with initial helpers (runs on prop changes)\n useEffect(() => {\n const addedEntries: [string, ContextHelperFn][] = [];\n\n if (contextHelpers) {\n for (const [name, fn] of Object.entries(contextHelpers)) {\n addContextHelper(name, fn);\n addedEntries.push([name, fn]);\n }\n }\n\n return () => {\n for (const [name, fn] of addedEntries) {\n // Only remove if the registry still points to the same function\n removeContextHelper(name, fn);\n }\n };\n }, [addContextHelper, contextHelpers, removeContextHelper]);\n\n const getAdditionalContext = useCallback(async () => {\n const contexts = await resolveAdditionalContext(helpers);\n return contexts as AdditionalContext[];\n }, [helpers]);\n\n const getContextHelpers = useCallback(() => {\n return helpers as ContextHelpers;\n }, [helpers]);\n\n const value = useMemo(\n () => ({\n getAdditionalContext,\n getContextHelpers,\n addContextHelper,\n removeContextHelper,\n }),\n [\n getAdditionalContext,\n getContextHelpers,\n addContextHelper,\n removeContextHelper,\n ],\n );\n\n return (\n <TamboContextHelpersContext.Provider value={value}>\n {children}\n </TamboContextHelpersContext.Provider>\n );\n};\n\n/**\n * Hook to access context helpers functionality.\n * Safe to call even when no provider is present: proxies to the global registry.\n * @returns The context helpers context props (registry-backed).\n */\nexport const useTamboContextHelpers = () => {\n const context = useContext(TamboContextHelpersContext);\n if (context) return context;\n\n // Fallback to global registry so the API is standalone outside any provider\n return {\n getAdditionalContext: async () => {\n throw new Error(\"No provider found\");\n },\n getContextHelpers: () => {\n throw new Error(\"No provider found\");\n },\n addContextHelper: (_name: string, _helper: ContextHelperFn) => {\n throw new Error(\"No provider found\");\n },\n removeContextHelper: (_name: string) => {\n throw new Error(\"No provider found\");\n },\n } as TamboContextHelpersContextProps;\n};\n"]}
1
+ {"version":3,"file":"tambo-context-helpers-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-context-helpers-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AAMf,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAsBvE,MAAM,0BAA0B,GAC9B,aAAa,CAAyC,IAAI,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAEpC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,EAAE;IACnC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAkC,EAAE,CAAC,CAAC;IAC5E,MAAM,gBAAgB,GAAG,WAAW,CAAC,CAAC,IAAY,EAAE,EAAmB,EAAE,EAAE;QACzE,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,IAAY,EAAE,EAAoB,EAAE,EAAE;QACrC,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,MAAM,EAAE,CAAC,IAAI,CAAC,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,CAAC,CAAC;QACL,oBAAoB;QACpB,iBAAiB;QACjB,gBAAgB;QAChB,mBAAmB;KACpB,CAAC,EACF;QACE,oBAAoB;QACpB,iBAAiB;QACjB,gBAAgB;QAChB,mBAAmB;KACpB,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC9C,QAAQ,CAC2B,CACvC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAE5B,gFAAgF;IAChF,OAAO;QACL,oBAAoB,EAAE,KAAK,IAAI,EAAE;YAC/B,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE;YACtB,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QACD,gBAAgB,EAAE,CAAC,KAAa,EAAE,OAAwB,EAAE,EAAE;YAC5D,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QACD,mBAAmB,EAAE,CAAC,KAAa,EAAE,EAAE;YACrC,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;KACiC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"../context-helpers\";\nimport { resolveAdditionalContext } from \"../context-helpers/registry\";\n\nexport interface TamboContextHelpersProviderProps {\n /**\n * A dictionary of context helper functions.\n * The key becomes the AdditionalContext.name and the function returns the value.\n * Return null/undefined to skip including that context.\n */\n contextHelpers?: ContextHelpers;\n}\n\nexport interface TamboContextHelpersContextProps {\n /** Get all additional context by running all helper functions */\n getAdditionalContext: () => Promise<AdditionalContext[]>;\n /** Get the current context helpers map */\n getContextHelpers: () => ContextHelpers;\n /** Add or update a context helper by name */\n addContextHelper: (name: string, helper: ContextHelperFn) => void;\n /** Remove a context helper by name */\n removeContextHelper: (name: string) => void;\n}\n\nconst TamboContextHelpersContext =\n createContext<TamboContextHelpersContextProps | null>(null);\n\n/**\n * Provider for managing additional context helpers.\n * Accepts a map of { key: () => any | null | undefined | Promise<any | null | undefined> }.\n * Returning null/undefined skips inclusion; returned values are wrapped as { name: key, context: value }.\n * @param props - The props for the TamboContextHelpersProvider.\n * @param props.contextHelpers - A dictionary of context helper functions keyed by context name.\n * @param props.children - The children to render.\n * @returns The provider that exposes context helper APIs via useTamboContextHelpers.\n */\nexport const TamboContextHelpersProvider: React.FC<\n PropsWithChildren<TamboContextHelpersProviderProps>\n> = ({ children, contextHelpers }) => {\n const [helpers, setHelpers] = useState<Record<string, ContextHelperFn>>({});\n const addContextHelper = useCallback((name: string, fn: ContextHelperFn) => {\n setHelpers((prev) => ({ ...prev, [name]: fn }));\n }, []);\n const removeContextHelper = useCallback(\n (name: string, fn?: ContextHelperFn) => {\n setHelpers((prev) => {\n const { [name]: registeredFn, ...rest } = prev;\n if (fn === undefined || registeredFn === fn) {\n return rest;\n }\n return prev;\n });\n },\n [],\n );\n // Hydrate the global registry with initial helpers (runs on prop changes)\n useEffect(() => {\n const addedEntries: [string, ContextHelperFn][] = [];\n\n if (contextHelpers) {\n for (const [name, fn] of Object.entries(contextHelpers)) {\n addContextHelper(name, fn);\n addedEntries.push([name, fn]);\n }\n }\n\n return () => {\n for (const [name, fn] of addedEntries) {\n // Only remove if the registry still points to the same function\n removeContextHelper(name, fn);\n }\n };\n }, [addContextHelper, contextHelpers, removeContextHelper]);\n\n const getAdditionalContext = useCallback(async () => {\n const contexts = await resolveAdditionalContext(helpers);\n return contexts as AdditionalContext[];\n }, [helpers]);\n\n const getContextHelpers = useCallback(() => {\n return helpers as ContextHelpers;\n }, [helpers]);\n\n const value = useMemo(\n () => ({\n getAdditionalContext,\n getContextHelpers,\n addContextHelper,\n removeContextHelper,\n }),\n [\n getAdditionalContext,\n getContextHelpers,\n addContextHelper,\n removeContextHelper,\n ],\n );\n\n return (\n <TamboContextHelpersContext.Provider value={value}>\n {children}\n </TamboContextHelpersContext.Provider>\n );\n};\n\n/**\n * Hook to access context helpers functionality.\n *\n * Behavior without a provider: this hook does NOT throw immediately. If it is\n * called outside of a `TamboContextHelpersProvider`, it returns a fallback\n * object whose methods will throw when invoked. This \"lazy-throw\" pattern is\n * intentional so the error surfaces at the actual point of use.\n * @returns The context helpers API when a provider is present; otherwise, a\n * fallback object whose methods throw if called.\n */\nexport const useTamboContextHelpers = () => {\n const context = useContext(TamboContextHelpersContext);\n if (context) return context;\n\n // No provider present: return methods that throw with a helpful error when used\n return {\n getAdditionalContext: async () => {\n throw new Error(\n \"useTamboContextHelpers must be used within a TamboContextHelpersProvider\",\n );\n },\n getContextHelpers: () => {\n throw new Error(\n \"useTamboContextHelpers must be used within a TamboContextHelpersProvider\",\n );\n },\n addContextHelper: (_name: string, _helper: ContextHelperFn) => {\n throw new Error(\n \"useTamboContextHelpers must be used within a TamboContextHelpersProvider\",\n );\n },\n removeContextHelper: (_name: string) => {\n throw new Error(\n \"useTamboContextHelpers must be used within a TamboContextHelpersProvider\",\n );\n },\n } as TamboContextHelpersContextProps;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAIrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0QjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;GAS3C,CAAC"}
1
+ {"version":3,"file":"tambo-interactable-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAKrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA6QjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;GAS3C,CAAC"}
@@ -5,6 +5,7 @@ import { z } from "zod";
5
5
  import { createInteractablesContextHelper } from "../context-helpers/current-interactables-context-helper";
6
6
  import { useTamboComponent } from "./tambo-component-provider";
7
7
  import { useTamboContextHelpers } from "./tambo-context-helpers-provider";
8
+ import { assertValidName } from "../util/validate-component-name";
8
9
  const TamboInteractableContext = createContext({
9
10
  interactableComponents: [],
10
11
  addInteractableComponent: () => "",
@@ -178,6 +179,8 @@ export const TamboInteractableProvider = ({ children, }) => {
178
179
  });
179
180
  }, [registerTool, updateInteractableComponentProps]);
180
181
  const addInteractableComponent = useCallback((component) => {
182
+ // Validate component name
183
+ assertValidName(component.name, "component");
181
184
  const id = `${component.name}-${Math.random().toString(36).slice(2, 11)}`;
182
185
  const newComponent = {
183
186
  ...component,
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,yDAAyD,CAAC;AAK3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,MAAM,wBAAwB,GAAG,aAAa,CAA2B;IACvE,sBAAsB,EAAE,EAAE;IAC1B,wBAAwB,EAAE,GAAG,EAAE,CAAC,EAAE;IAClC,2BAA2B,EAAE,GAAG,EAAE,GAAE,CAAC;IACrC,gCAAgC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC1C,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS;IACzC,+BAA+B,EAAE,GAAG,EAAE,CAAC,EAAE;IACzC,8BAA8B,EAAE,GAAG,EAAE,GAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAgC,CAAC,EACrE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,QAAQ,CAElE,EAAE,CAAC,CAAC;IACN,MAAM,EAAE,YAAY,EAAE,GAAG,iBAAiB,EAAE,CAAC;IAC7C,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAE3E,0CAA0C;IAC1C,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,OAAO,gCAAgC,CAAC,GAAG,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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,EAAE;IAClD,MAAM,EAAE,sBAAsB,EAAE,GAAG,oBAAoB,EAAE,CAAC;IAC1D,0DAA0D;IAC1D,MAAM,IAAI,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9C,GAAG,CAAC;QACJ,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE;KACtB,CAAC,CAAC,CAAC;IAEJ,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["// react-sdk/src/providers/tambo-interactable-provider.tsx\n\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\nconst TamboInteractableContext = createContext<TamboInteractableContext>({\n interactableComponents: [],\n addInteractableComponent: () => \"\",\n removeInteractableComponent: () => {},\n updateInteractableComponentProps: () => \"\",\n getInteractableComponent: () => undefined,\n getInteractableComponentsByName: () => [],\n clearAllInteractableComponents: () => {},\n});\n\n/**\n * The TamboInteractableProvider manages a list of components that are currently\n * interactable, allowing tambo to interact with them by updating their props. It also registers tools\n * for Tambo to perform CRUD operations on the components list.\n * @param props - The props for the TamboInteractableProvider\n * @param props.children - The children to wrap\n * @returns The TamboInteractableProvider component\n */\nexport const TamboInteractableProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [interactableComponents, setInteractableComponents] = useState<\n TamboInteractableComponent[]\n >([]);\n const { registerTool } = useTamboComponent();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Create a stable context helper function\n const contextHelper = useCallback(() => {\n return createInteractablesContextHelper(() => interactableComponents)();\n }, [interactableComponents]);\n\n // Register the default interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", contextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [contextHelper, addContextHelper, removeContextHelper]);\n\n useEffect(() => {\n if (interactableComponents.length > 0) {\n registerTool({\n name: \"get_all_interactable_components\",\n description:\n \"Only use this tool if the user is asking about interactable components.Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.\",\n tool: () => {\n return {\n components: interactableComponents,\n };\n },\n toolSchema: z.function().returns(\n z.object({\n components: z.array(\n z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n propsSchema: z.object({}).optional(),\n }),\n ),\n }),\n ),\n });\n\n registerTool({\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n })\n .optional(),\n error: z.string().optional(),\n }),\n ),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n setInteractableComponents((prev) =>\n prev.filter((c) => c.id !== componentId),\n );\n\n return {\n success: true,\n componentId,\n removedComponent: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n }),\n error: z.string().optional(),\n }),\n ),\n });\n }\n }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>): string => {\n if (!newProps || Object.keys(newProps).length === 0) {\n return `Warning: No props provided for component with ID ${id}.`;\n }\n\n setInteractableComponents((prev) => {\n const component = prev.find((c) => c.id === id);\n if (!component) {\n return prev;\n }\n\n // Compare props shallowly\n const propsChanged = Object.entries(newProps).some(([key, value]) => {\n return component.props[key] !== value;\n });\n\n if (!propsChanged) {\n return prev; // unchanged\n }\n\n // Apply partial update\n const updated = {\n ...component,\n props: { ...component.props, ...newProps },\n };\n\n const updatedComponents = [...prev];\n const idx = prev.findIndex((c) => c.id === id);\n updatedComponents[idx] = updated;\n\n return updatedComponents;\n });\n\n return \"Updated successfully\";\n },\n [],\n );\n\n const registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent) => {\n const schemaForArgs =\n typeof component.propsSchema === \"object\" &&\n \"describe\" in component.propsSchema &&\n \"partial\" in component.propsSchema\n ? (component.propsSchema as any).partial()\n : z.object({});\n\n registerTool({\n name: `update_interactable_component_${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name}). You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.`,\n tool: (componentId: string, newProps: any) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n toolSchema: z\n .function()\n .args(\n z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n schemaForArgs.describe(\n \"The props to update the component with. You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.\",\n ),\n )\n .returns(z.string()),\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n const id = `${component.name}-${Math.random().toString(36).slice(2, 11)}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n };\n\n registerInteractableComponentUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [registerInteractableComponentUpdateTool],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n (id: string) => {\n return interactableComponents.find((c) => c.id === id);\n },\n [interactableComponents],\n );\n\n const getInteractableComponentsByName = useCallback(\n (componentName: string) => {\n return interactableComponents.filter((c) => c.name === componentName);\n },\n [interactableComponents],\n );\n\n const clearAllInteractableComponents = useCallback(() => {\n setInteractableComponents([]);\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n };\n\n return (\n <TamboInteractableContext.Provider value={value}>\n {children}\n </TamboInteractableContext.Provider>\n );\n};\n\n/**\n * The useTamboInteractable hook provides access to the interactable component\n * management functions.\n * @returns The interactable component management functions\n */\nexport const useTamboInteractable = () => {\n return useContext(TamboInteractableContext);\n};\n\n/**\n * Hook to get a cloned snapshot of the current interactables.\n * Returns a shallow copy of the array with cloned items and props to prevent\n * external mutation from affecting internal state.\n * @returns The current interactables snapshot (cloned).\n */\nexport const useCurrentInteractablesSnapshot = () => {\n const { interactableComponents } = useTamboInteractable();\n // Clone the array and each item/props to prevent mutation\n const copy = interactableComponents.map((c) => ({\n ...c,\n props: { ...c.props },\n }));\n\n return copy;\n};\n"]}
1
+ {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA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EAAE,EAAE,CAAC,CAAC;QAC9C,GAAG,CAAC;QACJ,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE;KACtB,CAAC,CAAC,CAAC;IAEJ,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["// react-sdk/src/providers/tambo-interactable-provider.tsx\n\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\nimport { assertValidName } from \"../util/validate-component-name\";\n\nconst TamboInteractableContext = createContext<TamboInteractableContext>({\n interactableComponents: [],\n addInteractableComponent: () => \"\",\n removeInteractableComponent: () => {},\n updateInteractableComponentProps: () => \"\",\n getInteractableComponent: () => undefined,\n getInteractableComponentsByName: () => [],\n clearAllInteractableComponents: () => {},\n});\n\n/**\n * The TamboInteractableProvider manages a list of components that are currently\n * interactable, allowing tambo to interact with them by updating their props. It also registers tools\n * for Tambo to perform CRUD operations on the components list.\n * @param props - The props for the TamboInteractableProvider\n * @param props.children - The children to wrap\n * @returns The TamboInteractableProvider component\n */\nexport const TamboInteractableProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [interactableComponents, setInteractableComponents] = useState<\n TamboInteractableComponent[]\n >([]);\n const { registerTool } = useTamboComponent();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Create a stable context helper function\n const contextHelper = useCallback(() => {\n return createInteractablesContextHelper(() => interactableComponents)();\n }, [interactableComponents]);\n\n // Register the default interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", contextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [contextHelper, addContextHelper, removeContextHelper]);\n\n useEffect(() => {\n if (interactableComponents.length > 0) {\n registerTool({\n name: \"get_all_interactable_components\",\n description:\n \"Only use this tool if the user is asking about interactable components.Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.\",\n tool: () => {\n return {\n components: interactableComponents,\n };\n },\n toolSchema: z.function().returns(\n z.object({\n components: z.array(\n z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n propsSchema: z.object({}).optional(),\n }),\n ),\n }),\n ),\n });\n\n registerTool({\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n })\n .optional(),\n error: z.string().optional(),\n }),\n ),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n setInteractableComponents((prev) =>\n prev.filter((c) => c.id !== componentId),\n );\n\n return {\n success: true,\n componentId,\n removedComponent: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n }),\n error: z.string().optional(),\n }),\n ),\n });\n }\n }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>): string => {\n if (!newProps || Object.keys(newProps).length === 0) {\n return `Warning: No props provided for component with ID ${id}.`;\n }\n\n setInteractableComponents((prev) => {\n const component = prev.find((c) => c.id === id);\n if (!component) {\n return prev;\n }\n\n // Compare props shallowly\n const propsChanged = Object.entries(newProps).some(([key, value]) => {\n return component.props[key] !== value;\n });\n\n if (!propsChanged) {\n return prev; // unchanged\n }\n\n // Apply partial update\n const updated = {\n ...component,\n props: { ...component.props, ...newProps },\n };\n\n const updatedComponents = [...prev];\n const idx = prev.findIndex((c) => c.id === id);\n updatedComponents[idx] = updated;\n\n return updatedComponents;\n });\n\n return \"Updated successfully\";\n },\n [],\n );\n\n const registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent) => {\n const schemaForArgs =\n typeof component.propsSchema === \"object\" &&\n \"describe\" in component.propsSchema &&\n \"partial\" in component.propsSchema\n ? (component.propsSchema as any).partial()\n : z.object({});\n\n registerTool({\n name: `update_interactable_component_${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name}). You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.`,\n tool: (componentId: string, newProps: any) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n toolSchema: z\n .function()\n .args(\n z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n schemaForArgs.describe(\n \"The props to update the component with. You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.\",\n ),\n )\n .returns(z.string()),\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n // Validate component name\n assertValidName(component.name, \"component\");\n\n const id = `${component.name}-${Math.random().toString(36).slice(2, 11)}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n };\n\n registerInteractableComponentUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [registerInteractableComponentUpdateTool],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n (id: string) => {\n return interactableComponents.find((c) => c.id === id);\n },\n [interactableComponents],\n );\n\n const getInteractableComponentsByName = useCallback(\n (componentName: string) => {\n return interactableComponents.filter((c) => c.name === componentName);\n },\n [interactableComponents],\n );\n\n const clearAllInteractableComponents = useCallback(() => {\n setInteractableComponents([]);\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n };\n\n return (\n <TamboInteractableContext.Provider value={value}>\n {children}\n </TamboInteractableContext.Provider>\n );\n};\n\n/**\n * The useTamboInteractable hook provides access to the interactable component\n * management functions.\n * @returns The interactable component management functions\n */\nexport const useTamboInteractable = () => {\n return useContext(TamboInteractableContext);\n};\n\n/**\n * Hook to get a cloned snapshot of the current interactables.\n * Returns a shallow copy of the array with cloned items and props to prevent\n * external mutation from affecting internal state.\n * @returns The current interactables snapshot (cloned).\n */\nexport const useCurrentInteractablesSnapshot = () => {\n const { interactableComponents } = useTamboInteractable();\n // Clone the array and each item/props to prevent mutation\n const copy = interactableComponents.map((c) => ({\n ...c,\n props: { ...c.props },\n }));\n\n return copy;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The TamboPropsStreamProvider provides a context for managing stream states
2
+ * The TamboPropStreamProvider provides a context for managing stream states
3
3
  * with compound components for Pending, Streaming, and Success states.
4
4
  * @param children - The children to wrap
5
5
  * @returns The TamboPropStreamProvider component
@@ -3,7 +3,7 @@ import { TamboPropStreamProviderComponent } from "./provider";
3
3
  import { Streaming } from "./streaming";
4
4
  import { Success } from "./success";
5
5
  /**
6
- * The TamboPropsStreamProvider provides a context for managing stream states
6
+ * The TamboPropStreamProvider provides a context for managing stream states
7
7
  * with compound components for Pending, Streaming, and Success states.
8
8
  * @param children - The children to wrap
9
9
  * @returns The TamboPropStreamProvider component
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/tambo-prop-stream-provider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAClD,gCAAgC,EAChC;IACE,SAAS;IACT,OAAO;IACP,OAAO;CACR,CACF,CAAC;AAEF,0CAA0C;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,cAAc,SAAS,CAAC","sourcesContent":["import { Pending } from \"./pending\";\nimport { TamboPropStreamProviderComponent } from \"./provider\";\nimport { Streaming } from \"./streaming\";\nimport { Success } from \"./success\";\n\n/**\n * The TamboPropsStreamProvider provides a context for managing stream states\n * with compound components for Pending, Streaming, and Success states.\n * @param children - The children to wrap\n * @returns The TamboPropStreamProvider component\n */\nexport const TamboPropStreamProvider = Object.assign(\n TamboPropStreamProviderComponent,\n {\n Streaming,\n Pending,\n Success,\n },\n);\n\n// Re-export components for individual use\nexport { Pending } from \"./pending\";\nexport { useTamboStream } from \"./provider\";\nexport { Streaming } from \"./streaming\";\nexport { Success } from \"./success\";\nexport * from \"./types\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/tambo-prop-stream-provider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAClD,gCAAgC,EAChC;IACE,SAAS;IACT,OAAO;IACP,OAAO;CACR,CACF,CAAC;AAEF,0CAA0C;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,cAAc,SAAS,CAAC","sourcesContent":["import { Pending } from \"./pending\";\nimport { TamboPropStreamProviderComponent } from \"./provider\";\nimport { Streaming } from \"./streaming\";\nimport { Success } from \"./success\";\n\n/**\n * The TamboPropStreamProvider provides a context for managing stream states\n * with compound components for Pending, Streaming, and Success states.\n * @param children - The children to wrap\n * @returns The TamboPropStreamProvider component\n */\nexport const TamboPropStreamProvider = Object.assign(\n TamboPropStreamProviderComponent,\n {\n Streaming,\n Pending,\n Success,\n },\n);\n\n// Re-export components for individual use\nexport { Pending } from \"./pending\";\nexport { useTamboStream } from \"./provider\";\nexport { Streaming } from \"./streaming\";\nexport { Success } from \"./success\";\nexport * from \"./types\";\n"]}
@@ -18,7 +18,7 @@ import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadP
18
18
  * @param props.tools - The tools to register
19
19
  * @param props.streaming - Whether to stream the response by default. Defaults to true.
20
20
  * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled
21
- * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)
21
+ * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)
22
22
  * @param props.contextKey - Optional context key to be used in the thread input provider
23
23
  * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
24
24
  * @returns The TamboProvider component
@@ -19,7 +19,7 @@ import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
19
19
  * @param props.tools - The tools to register
20
20
  * @param props.streaming - Whether to stream the response by default. Defaults to true.
21
21
  * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled
22
- * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)
22
+ * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)
23
23
  * @param props.contextKey - Optional context key to be used in the thread input provider
24
24
  * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
25
25
  * @returns The TamboProvider component
@@ -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;AAE5E,OAAO,EAEL,mBAAmB,EAEnB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,2BAA2B,EAE3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,GAEzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,mBAAmB,EAEnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,aAAa,GAQtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,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OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;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 { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\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, the current thread context, and interactable components.\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 * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n onCallUnregisteredTool,\n}) => {\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 userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const isUpdatingToken = useIsTamboTokenUpdating();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\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, the current thread context,\n * and interactable component management.\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;AAE5E,OAAO,EAEL,mBAAmB,EAEnB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,2BAA2B,EAE3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,GAEzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,mBAAmB,EAEnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,aAAa,GAQ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tD,MAAM,cAAc,GAAG,sBAAsB,EAAE,CAAC;IAEhD,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;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 { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\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, the current thread context, and interactable components.\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 * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n onCallUnregisteredTool,\n}) => {\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 userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const isUpdatingToken = useIsTamboTokenUpdating();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\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, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAGrC,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACxC,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EA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pD,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACrE,sBAAsB,CAAC,EAAE,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,eAAO,MAAM,oBAAoB,qCAoB/B,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IAEpB;;;;;;;OAOG;IACH,sBAAsB,CAAC,EAAE,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CA8J9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAE5B,CAAC"}
@@ -2,6 +2,7 @@
2
2
  import React, { createContext, useCallback, useContext, useEffect, useState, } from "react";
3
3
  import { ZodSchema } from "zod";
4
4
  import zodToJsonSchema from "zod-to-json-schema";
5
+ import { assertValidName } from "../util/validate-component-name";
5
6
  import { assertNoZodRecord } from "../util/validate-zod-schema";
6
7
  export const TamboRegistryContext = createContext({
7
8
  componentList: {},
@@ -39,6 +40,8 @@ export const TamboRegistryProvider = ({ children, components: userComponents, to
39
40
  const [toolRegistry, setToolRegistry] = useState({});
40
41
  const [componentToolAssociations, setComponentToolAssociations] = useState({});
41
42
  const registerTool = useCallback((tool, warnOnOverwrite = true) => {
43
+ // Validate tool name
44
+ assertValidName(tool.name, "tool");
42
45
  // Validate tool schemas
43
46
  if (tool.toolSchema && isZodSchema(tool.toolSchema)) {
44
47
  assertNoZodRecord(tool.toolSchema, `toolSchema of tool "${tool.name}"`);
@@ -57,16 +60,24 @@ export const TamboRegistryProvider = ({ children, components: userComponents, to
57
60
  tools.forEach((tool) => registerTool(tool, warnOnOverwrite));
58
61
  }, [registerTool]);
59
62
  const addToolAssociation = useCallback((componentName, tool) => {
63
+ // Validate component and tool names
64
+ assertValidName(componentName, "component");
65
+ assertValidName(tool.name, "tool");
60
66
  if (!componentList[componentName]) {
61
67
  throw new Error(`Component ${componentName} not found in registry`);
62
68
  }
69
+ if (!toolRegistry[tool.name]) {
70
+ throw new Error(`Tool ${tool.name} not found in registry`);
71
+ }
63
72
  setComponentToolAssociations((prev) => ({
64
73
  ...prev,
65
74
  [componentName]: [...(prev[componentName] || []), tool.name],
66
75
  }));
67
- }, [componentList]);
76
+ }, [componentList, toolRegistry]);
68
77
  const registerComponent = useCallback((options, warnOnOverwrite = true) => {
69
78
  const { name, description, component, propsSchema, propsDefinition, loadingComponent, associatedTools, } = options;
79
+ // Validate component name
80
+ assertValidName(name, "component");
70
81
  // Validate that at least one props definition is provided
71
82
  if (!propsSchema && !propsDefinition) {
72
83
  throw new Error(`Component ${name} must have either propsSchema (recommended) or propsDefinition defined`);
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,eAA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,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,WAAgB;IACpC,OAAO,CACL,WAAW;QACX,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,KAAK,QAAQ;QAC7B,WAAW,CAAC,UAAU,CACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,GAAG,YAAY,SAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,6CAA6C;IAC7C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAAW,CAAC,SAAS,KAAK,UAAU;QAC5C,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\nimport { assertNoZodRecord } from \"../util/validate-zod-schema\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\nexport const TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n\n /**\n * A function to call when an unknown tool is called. If this function is not\n * provided, an error will be thrown when a tool call is requested by the\n * server.\n *\n * Note that this is generally only for agents, where the agent code may\n * request tool calls that are not registered in the tool registry.\n */\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @param props.onCallUnregisteredTool - The function to call when an unknown tool is called (optional)\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({\n children,\n components: userComponents,\n tools: userTools,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n // Validate tool schemas\n if (tool.toolSchema && isZodSchema(tool.toolSchema)) {\n assertNoZodRecord(tool.toolSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include z.record()\n if (propsSchema && isZodSchema(propsSchema)) {\n assertNoZodRecord(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n onCallUnregisteredTool,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
1
+ {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACh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C;AAC1C,CAAC,CAAC;AACF,SAAS,kBAAkB,CACzB,eAAoB,EACpB,WAAgB,EAChB,IAAY;IAEZ,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;QACxE,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,IAAI,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,eAAe,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,oBAAoB,IAAI,+BAA+B,EACvD,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,qFAAqF;IACrF,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,WAAgB;IACpC,OAAO,CACL,WAAW;QACX,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,KAAK,QAAQ;QAC7B,WAAW,CAAC,UAAU,CACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,GAAG,YAAY,SAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,6CAA6C;IAC7C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAAW,CAAC,SAAS,KAAK,UAAU;QAC5C,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\nimport { assertValidName } from \"../util/validate-component-name\";\nimport { assertNoZodRecord } from \"../util/validate-zod-schema\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\nexport const TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n\n /**\n * A function to call when an unknown tool is called. If this function is not\n * provided, an error will be thrown when a tool call is requested by the\n * server.\n *\n * Note that this is generally only for agents, where the agent code may\n * request tool calls that are not registered in the tool registry.\n */\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @param props.onCallUnregisteredTool - The function to call when an unknown tool is called (optional)\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({\n children,\n components: userComponents,\n tools: userTools,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n if (tool.toolSchema && isZodSchema(tool.toolSchema)) {\n assertNoZodRecord(tool.toolSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(tool.name, \"tool\");\n\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolRegistry[tool.name]) {\n throw new Error(`Tool ${tool.name} not found in registry`);\n }\n\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList, toolRegistry],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include z.record()\n if (propsSchema && isZodSchema(propsSchema)) {\n assertNoZodRecord(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n onCallUnregisteredTool,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Validates that a name matches OpenAI function name requirements
3
+ * @param name The name to validate
4
+ * @param contextName The context name (e.g., "component", "tool")
5
+ */
6
+ export declare function assertValidName(name: string, contextName: string): void;
7
+ //# sourceMappingURL=validate-component-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-component-name.d.ts","sourceRoot":"","sources":["../../src/util/validate-component-name.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAMvE"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Validates that a name matches OpenAI function name requirements
3
+ * @param name The name to validate
4
+ * @param contextName The context name (e.g., "component", "tool")
5
+ */
6
+ export function assertValidName(name, contextName) {
7
+ if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
8
+ throw new Error(`${contextName} "${name}" must only contain letters, numbers, underscores, and hyphens.`);
9
+ }
10
+ }
11
+ //# sourceMappingURL=validate-component-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-component-name.js","sourceRoot":"","sources":["../../src/util/validate-component-name.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,WAAmB;IAC/D,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,GAAG,WAAW,KAAK,IAAI,iEAAiE,CACzF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Validates that a name matches OpenAI function name requirements\n * @param name The name to validate\n * @param contextName The context name (e.g., \"component\", \"tool\")\n */\nexport function assertValidName(name: string, contextName: string): void {\n if (!/^[a-zA-Z0-9_-]+$/.test(name)) {\n throw new Error(\n `${contextName} \"${name}\" must only contain letters, numbers, underscores, and hyphens.`,\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "React client package for Tambo AI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,9 +67,10 @@
67
67
  "react-dom": "^18.0.0 || ^19.0.0"
68
68
  },
69
69
  "dependencies": {
70
- "@modelcontextprotocol/sdk": "^1.17.4",
71
- "@tambo-ai/typescript-sdk": "^0.71.0",
72
- "@tanstack/react-query": "^5.87.4",
70
+ "@modelcontextprotocol/sdk": "^1.18.2",
71
+ "@tambo-ai/typescript-sdk": "^0.72.0",
72
+ "@tanstack/react-query": "^5.90.2",
73
+ "fast-equals": "^5.3.2",
73
74
  "partial-json": "^0.1.7",
74
75
  "react-fast-compare": "^3.2.2",
75
76
  "ts-essentials": "^10.1.1",
@@ -79,7 +80,7 @@
79
80
  "zod-to-json-schema": "^3.24.6"
80
81
  },
81
82
  "devDependencies": {
82
- "@eslint/js": "^9.35.0",
83
+ "@eslint/js": "^9.36.0",
83
84
  "@tambo-ai/eslint-config": "*",
84
85
  "@tambo-ai/typescript-config": "*",
85
86
  "@testing-library/jest-dom": "^6.8.0",
@@ -90,19 +91,19 @@
90
91
  "@types/react": "^18.3.23",
91
92
  "@types/react-dom": "^18.3.7",
92
93
  "concurrently": "^9.2.1",
93
- "eslint": "^9.35.0",
94
- "eslint-plugin-jsdoc": "^58.1.0",
94
+ "eslint": "^9.36.0",
95
+ "eslint-plugin-jsdoc": "^60.5.0",
95
96
  "eslint-plugin-react": "^7.37.5",
96
97
  "eslint-plugin-react-hooks": "^5.1.0",
97
- "jest": "^30.1.3",
98
- "jest-environment-jsdom": "^30.1.2",
98
+ "jest": "^30.2.0",
99
+ "jest-environment-jsdom": "^30.2.0",
99
100
  "lint-staged": "^16.1.6",
100
101
  "prettier": "^3.6.2",
101
102
  "prettier-2": "npm:prettier@^2",
102
103
  "react": "^18.3.1",
103
104
  "react-dom": "^18.3.1",
104
- "ts-jest": "^29.4.2",
105
+ "ts-jest": "^29.4.4",
105
106
  "typescript": "^5.9.2",
106
- "typescript-eslint": "^8.44.0"
107
+ "typescript-eslint": "^8.45.0"
107
108
  }
108
109
  }