@tambo-ai/react 0.46.4 → 0.47.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 (31) hide show
  1. package/dist/context-helpers/__tests__/context-helpers-provider.test.js +9 -5
  2. package/dist/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -1
  3. package/dist/context-helpers/registry.d.ts +1 -22
  4. package/dist/context-helpers/registry.d.ts.map +1 -1
  5. package/dist/context-helpers/registry.js +1 -35
  6. package/dist/context-helpers/registry.js.map +1 -1
  7. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
  8. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  9. package/dist/providers/tambo-context-helpers-provider.d.ts +1 -1
  10. package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  11. package/dist/providers/tambo-context-helpers-provider.js +33 -21
  12. package/dist/providers/tambo-context-helpers-provider.js.map +1 -1
  13. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  14. package/dist/providers/tambo-interactable-provider.js +85 -83
  15. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  16. package/esm/context-helpers/__tests__/context-helpers-provider.test.js +10 -6
  17. package/esm/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -1
  18. package/esm/context-helpers/registry.d.ts +1 -22
  19. package/esm/context-helpers/registry.d.ts.map +1 -1
  20. package/esm/context-helpers/registry.js +1 -31
  21. package/esm/context-helpers/registry.js.map +1 -1
  22. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
  23. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  24. package/esm/providers/tambo-context-helpers-provider.d.ts +1 -1
  25. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  26. package/esm/providers/tambo-context-helpers-provider.js +35 -23
  27. package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
  28. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  29. package/esm/providers/tambo-interactable-provider.js +85 -83
  30. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  31. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-context-helpers-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,2EAA2E;IAC3E,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,CAAC,EAAE,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,wCAAwC;IACxC,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE,CAAC,CAC/D,oBAAC,2BAA2B,QAAE,QAAQ,CAA+B,CACtE,CAAC;IAEF,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC;;;WAGG;QACH,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;YAC7E,MAAM,UAAU,GAAG,IAAI;iBACpB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC;iBACvB,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAChC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,sBAAsB,EAAE,CAAC,CAAC;YAE9D,mCAAmC;YACnC,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,C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AAQ,CAAC,CAAC,cAAc,CAAC;YAC9B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SAC3B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../../context-helpers\";\nimport { setHelpers } from \"../../context-helpers/registry\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../tambo-context-helpers-provider\";\n\n/**\n * Test suite for TamboContextHelpersProvider (simplified API, registry-backed)\n *\n * The simplified API:\n * - Accepts a plain map of { key: () => any | null | undefined | Promise<any | null | undefined> }.\n * - The key becomes the context name sent to the model.\n * - Returning null/undefined from a helper skips inclusion.\n * - Prebuilt helpers are just functions (e.g., prebuiltUserTime, prebuiltUserPage).\n *\n * The hook is now registry-backed and safe to call outside a provider. When used\n * outside a provider, it proxies to a global registry and still works.\n */\ndescribe(\"TamboContextHelpersProvider\", () => {\n // Ensure registry is clean for each test to avoid cross-test contamination\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n // Base wrapper with no helpers provided\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n );\n\n describe(\"useTamboContextHelpers\", () => {\n /**\n * NOTE: The hook is registry-backed and safe outside provider. It should not throw.\n * This replaces the previous behavior that threw without a provider.\n */\n it(\"should be safe outside provider (registry-backed no provider)\", async () => {\n const consoleSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n const { result } = renderHook(() => useTamboContextHelpers());\n\n // Should return callable functions\n expect(typeof result.current.getAdditionalContext).toBe(\"function\");\n expect(typeof result.current.getContextHelpers).toBe(\"function\");\n expect(typeof result.current.addContextHelper).toBe(\"function\");\n expect(typeof result.current.removeContextHelper).toBe(\"function\");\n\n // Starts empty\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n // Add a helper and verify\n act(() => {\n result.current.addContextHelper(\"outsideHelper\", () => ({ ok: true }));\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"outsideHelper\",\n context: { ok: true },\n });\n\n // Cleanup\n act(() => {\n result.current.removeContextHelper(\"outsideHelper\");\n });\n consoleSpy.mockRestore();\n });\n\n /**\n * Verifies that the hook returns the expected API functions when used within a provider.\n */\n it(\"should provide context helpers functions (inside provider)\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n expect(result.current).toHaveProperty(\"getAdditionalContext\");\n expect(result.current).toHaveProperty(\"getContextHelpers\");\n expect(result.current).toHaveProperty(\"addContextHelper\");\n expect(result.current).toHaveProperty(\"removeContextHelper\");\n });\n\n /**\n * With no helpers provided, no additional context should be returned.\n */\n it(\"should return no additional context when no helpers are provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n /**\n * When helpers are provided, getAdditionalContext should aggregate them.\n * Note: prebuiltUserPage may be null in non-browser envs, so we only assert userTime when present.\n */\n it(\"should get additional context when helpers are provided\", async () => {\n const withHelpers = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withHelpers,\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n // userTime should be present from prebuilt helper\n expect(names).toContain(\"userTime\");\n // userPage may be absent on server; do not assert strictly\n });\n\n /**\n * Errors thrown by helper functions should be caught and skipped, not crash the system.\n */\n it(\"should handle errors in context helper functions gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n const badHelper = () => {\n throw new Error(\"Test error\");\n };\n\n const withBadHelper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider contextHelpers={{ badHelper }}>\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withBadHelper,\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts.length).toBe(0);\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper badHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n });\n});\n\n/**\n * Test suite for Custom Context Helpers using the simplified API.\n *\n * Focuses on:\n * - Passing custom helpers via the provider prop.\n * - Overriding prebuilt helpers with custom implementations.\n * - Dynamic add/remove helper management at runtime.\n * - Supporting both sync and async helpers.\n * - Using the config key as the context name.\n * - Graceful error handling for custom helpers.\n */\ndescribe(\"Custom Context Helpers via contextHelpers config\", () => {\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n /**\n * Custom helpers can be added through the provider configuration.\n * The key becomes the context name and the function returns the raw value.\n */\n it(\"should accept custom helpers through contextHelpers config\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customData: async () => ({ custom: \"value\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"customData\",\n context: { custom: \"value\" },\n });\n });\n\n /**\n * Built-in helpers can be overridden by providing a function under the same key.\n */\n it(\"should allow custom helpers to override built-in ones\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: async () => ({ customTime: \"override\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const userTimeContext = contexts.find((c) => c.name === \"userTime\");\n expect(userTimeContext?.context).toEqual({ customTime: \"override\" });\n });\n\n /**\n * Helpers can be added dynamically at runtime via addContextHelper.\n */\n it(\"should handle dynamic addition of custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Initially none\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n act(() => {\n result.current.addContextHelper(\"dynamicHelper\", async () => ({\n dynamic: true,\n }));\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"dynamicHelper\",\n context: { dynamic: true },\n });\n });\n\n /**\n * Helpers can be removed dynamically via removeContextHelper.\n */\n it(\"should handle dynamic removal of context helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customHelper: async () => ({ test: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify exists\n let contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeDefined();\n\n // Remove\n act(() => {\n result.current.removeContextHelper(\"customHelper\");\n });\n\n // Verify removed\n contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeUndefined();\n });\n\n /**\n * Multiple custom helpers should be supported; helpers returning null/undefined are skipped.\n */\n it(\"should handle multiple custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n helper1: async () => ({ data: \"one\" }),\n helper2: async () => ({ data: \"two\" }),\n helper3: () => null, // disabled by returning null\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"helper1\",\n context: { data: \"one\" },\n });\n expect(contexts).toContainEqual({\n name: \"helper2\",\n context: { data: \"two\" },\n });\n expect(contexts.find((c) => c.name === \"helper3\")).toBeUndefined();\n });\n\n /**\n * Both synchronous and asynchronous helpers should be supported.\n */\n it(\"should handle sync and async custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n syncHelper: () => ({ sync: true }),\n asyncHelper: async () => {\n await new Promise((resolve) => setTimeout(resolve, 10));\n return { async: true };\n },\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"syncHelper\",\n context: { sync: true },\n });\n expect(contexts).toContainEqual({\n name: \"asyncHelper\",\n context: { async: true },\n });\n });\n\n /**\n * The key used in the contextHelpers map becomes the context name.\n */\n it(\"should use key name as context name for custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n myCustomKey: async () => ({ value: \"test\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"myCustomKey\",\n context: { value: \"test\" },\n });\n });\n\n /**\n * Errors thrown by custom helpers should be logged and skipped, not crash the system.\n */\n it(\"should handle errors in custom helpers gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n errorHelper: async () => {\n throw new Error(\"Custom helper error\");\n },\n goodHelper: async () => ({ good: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"goodHelper\",\n context: { good: \"data\" },\n });\n expect(contexts.find((c) => c.name === \"errorHelper\")).toBeUndefined();\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper errorHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n\n /**\n * Removing non-existent helpers should be a no-op without throwing errors.\n */\n it(\"should handle removing non-existent helper gracefully\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n expect(() => {\n act(() => {\n result.current.removeContextHelper(\"nonExistent\");\n });\n }).not.toThrow();\n });\n\n /**\n * Adding with an existing name should update/replace the helper implementation.\n */\n it(\"should allow updating existing helper via addContextHelper\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n testHelper: async () => ({ original: true }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify original helper\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { original: true },\n });\n\n // Update the helper\n act(() => {\n result.current.addContextHelper(\"testHelper\", async () => ({\n updated: true,\n }));\n });\n\n // Verify updated helper\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { updated: true },\n });\n });\n});\n"]}
1
+ {"version":3,"file":"tambo-context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-context-helpers-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,6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,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC;YAC9B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5B,CAAC,CAAC;QAEH,oBAAoB;QACpB,GAAG,CAAC,GAAG,EAAE;YACP,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;gBACzD,OAAO,EAAE,IAAI;aACd,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,wBAAwB;QACxB,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC;YAC9B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SAC3B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport React from \"react\";\nimport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../../context-helpers\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../tambo-context-helpers-provider\";\n\n/**\n * Test suite for TamboContextHelpersProvider (simplified API, registry-backed)\n *\n * The simplified API:\n * - Accepts a plain map of { key: () => any | null | undefined | Promise<any | null | undefined> }.\n * - The key becomes the context name sent to the model.\n * - Returning null/undefined from a helper skips inclusion.\n * - Prebuilt helpers are just functions (e.g., prebuiltUserTime, prebuiltUserPage).\n *\n * The hook is now registry-backed and safe to call outside a provider. When used\n * outside a provider, it proxies to a global registry and still works.\n */\ndescribe(\"TamboContextHelpersProvider\", () => {\n // Ensure registry is clean for each test to avoid cross-test contamination\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n // Base wrapper with no helpers provided\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n );\n\n describe(\"useTamboContextHelpers\", () => {\n /**\n * Verifies that the hook returns the expected API functions when used within a provider.\n */\n it(\"should provide context helpers functions (inside provider)\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n expect(result.current).toHaveProperty(\"getAdditionalContext\");\n expect(result.current).toHaveProperty(\"getContextHelpers\");\n expect(result.current).toHaveProperty(\"addContextHelper\");\n expect(result.current).toHaveProperty(\"removeContextHelper\");\n });\n\n /**\n * With no helpers provided, no additional context should be returned.\n */\n it(\"should return no additional context when no helpers are provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper,\n });\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n /**\n * When helpers are provided, getAdditionalContext should aggregate them.\n * Note: prebuiltUserPage may be null in non-browser envs, so we only assert userTime when present.\n */\n it(\"should get additional context when helpers are provided\", async () => {\n const withHelpers = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withHelpers,\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n // userTime should be present from prebuilt helper\n expect(names).toContain(\"userTime\");\n // userPage may be absent on server; do not assert strictly\n });\n\n /**\n * Errors thrown by helper functions should be caught and skipped, not crash the system.\n */\n it(\"should handle errors in context helper functions gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n const badHelper = () => {\n throw new Error(\"Test error\");\n };\n\n const withBadHelper = ({ children }: { children: React.ReactNode }) => (\n <TamboContextHelpersProvider contextHelpers={{ badHelper }}>\n {children}\n </TamboContextHelpersProvider>\n );\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: withBadHelper,\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts.length).toBe(0);\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper badHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n });\n});\n\n/**\n * Test suite for Custom Context Helpers using the simplified API.\n *\n * Focuses on:\n * - Passing custom helpers via the provider prop.\n * - Overriding prebuilt helpers with custom implementations.\n * - Dynamic add/remove helper management at runtime.\n * - Supporting both sync and async helpers.\n * - Using the config key as the context name.\n * - Graceful error handling for custom helpers.\n */\ndescribe(\"Custom Context Helpers via contextHelpers config\", () => {\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n /**\n * Custom helpers can be added through the provider configuration.\n * The key becomes the context name and the function returns the raw value.\n */\n it(\"should accept custom helpers through contextHelpers config\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customData: async () => ({ custom: \"value\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"customData\",\n context: { custom: \"value\" },\n });\n });\n\n /**\n * Built-in helpers can be overridden by providing a function under the same key.\n */\n it(\"should allow custom helpers to override built-in ones\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n userTime: async () => ({ customTime: \"override\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const userTimeContext = contexts.find((c) => c.name === \"userTime\");\n expect(userTimeContext?.context).toEqual({ customTime: \"override\" });\n });\n\n /**\n * Helpers can be added dynamically at runtime via addContextHelper.\n */\n it(\"should handle dynamic addition of custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Initially none\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n act(() => {\n result.current.addContextHelper(\"dynamicHelper\", async () => ({\n dynamic: true,\n }));\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"dynamicHelper\",\n context: { dynamic: true },\n });\n });\n\n /**\n * Helpers can be removed dynamically via removeContextHelper.\n */\n it(\"should handle dynamic removal of context helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n customHelper: async () => ({ test: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify exists\n let contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeDefined();\n\n // Remove\n act(() => {\n result.current.removeContextHelper(\"customHelper\");\n });\n\n // Verify removed\n contexts = await result.current.getAdditionalContext();\n expect(contexts.find((c) => c.name === \"customHelper\")).toBeUndefined();\n });\n\n /**\n * Multiple custom helpers should be supported; helpers returning null/undefined are skipped.\n */\n it(\"should handle multiple custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n helper1: async () => ({ data: \"one\" }),\n helper2: async () => ({ data: \"two\" }),\n helper3: () => null, // disabled by returning null\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"helper1\",\n context: { data: \"one\" },\n });\n expect(contexts).toContainEqual({\n name: \"helper2\",\n context: { data: \"two\" },\n });\n expect(contexts.find((c) => c.name === \"helper3\")).toBeUndefined();\n });\n\n /**\n * Both synchronous and asynchronous helpers should be supported.\n */\n it(\"should handle sync and async custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n syncHelper: () => ({ sync: true }),\n asyncHelper: async () => {\n await new Promise((resolve) => setTimeout(resolve, 10));\n return { async: true };\n },\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"syncHelper\",\n context: { sync: true },\n });\n expect(contexts).toContainEqual({\n name: \"asyncHelper\",\n context: { async: true },\n });\n });\n\n /**\n * The key used in the contextHelpers map becomes the context name.\n */\n it(\"should use key name as context name for custom helpers\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n myCustomKey: async () => ({ value: \"test\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"myCustomKey\",\n context: { value: \"test\" },\n });\n });\n\n /**\n * Errors thrown by custom helpers should be logged and skipped, not crash the system.\n */\n it(\"should handle errors in custom helpers gracefully\", async () => {\n const consoleErrorSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n errorHelper: async () => {\n throw new Error(\"Custom helper error\");\n },\n goodHelper: async () => ({ good: \"data\" }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"goodHelper\",\n context: { good: \"data\" },\n });\n expect(contexts.find((c) => c.name === \"errorHelper\")).toBeUndefined();\n expect(consoleErrorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"Error running context helper errorHelper\"),\n expect.any(Error),\n );\n consoleErrorSpy.mockRestore();\n });\n\n /**\n * Removing non-existent helpers should be a no-op without throwing errors.\n */\n it(\"should handle removing non-existent helper gracefully\", () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider contextHelpers={{}}>\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n expect(() => {\n act(() => {\n result.current.removeContextHelper(\"nonExistent\");\n });\n }).not.toThrow();\n });\n\n /**\n * Adding with an existing name should update/replace the helper implementation.\n */\n it(\"should allow updating existing helper via addContextHelper\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: ({ children }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n testHelper: async () => ({ original: true }),\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n ),\n });\n\n // Verify original helper\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { original: true },\n });\n\n // Update the helper\n act(() => {\n result.current.addContextHelper(\"testHelper\", async () => ({\n updated: true,\n }));\n });\n\n // Verify updated helper\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toContainEqual({\n name: \"testHelper\",\n context: { updated: true },\n });\n });\n});\n"]}
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from "react";
2
- import { AdditionalContext, ContextHelpers, ContextHelperFn } from "../context-helpers";
2
+ import { AdditionalContext, ContextHelperFn, ContextHelpers } from "../context-helpers";
3
3
  export interface TamboContextHelpersProviderProps {
4
4
  /**
5
5
  * A dictionary of context helper functions.
@@ -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,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAQ5B,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,CAgEpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,uCAalC,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;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,uCAmBlC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import React, { createContext, useCallback, useContext, useMemo, } from "react";
3
- import { addHelper, getHelpers, removeHelper as removeGlobalHelper, resolveAdditionalContext, } from "../context-helpers/registry";
2
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
3
+ import { resolveAdditionalContext } from "../context-helpers/registry";
4
4
  const TamboContextHelpersContext = createContext(null);
5
5
  /**
6
6
  * Provider for managing additional context helpers.
@@ -12,38 +12,42 @@ const TamboContextHelpersContext = createContext(null);
12
12
  * @returns The provider that exposes context helper APIs via useTamboContextHelpers.
13
13
  */
14
14
  export const TamboContextHelpersProvider = ({ children, contextHelpers }) => {
15
+ const [helpers, setHelpers] = useState({});
16
+ const addContextHelper = useCallback((name, fn) => {
17
+ setHelpers((prev) => ({ ...prev, [name]: fn }));
18
+ }, []);
19
+ const removeContextHelper = useCallback((name, fn) => {
20
+ setHelpers((prev) => {
21
+ const { [name]: registeredFn, ...rest } = prev;
22
+ if (fn === undefined || registeredFn === fn) {
23
+ return rest;
24
+ }
25
+ return prev;
26
+ });
27
+ }, []);
15
28
  // Hydrate the global registry with initial helpers (runs on prop changes)
16
- React.useEffect(() => {
29
+ useEffect(() => {
17
30
  const addedEntries = [];
18
31
  if (contextHelpers) {
19
32
  for (const [name, fn] of Object.entries(contextHelpers)) {
20
- addHelper(name, fn);
33
+ addContextHelper(name, fn);
21
34
  addedEntries.push([name, fn]);
22
35
  }
23
36
  }
24
37
  return () => {
25
- const current = getHelpers();
26
38
  for (const [name, fn] of addedEntries) {
27
39
  // Only remove if the registry still points to the same function
28
- if (current[name] === fn) {
29
- removeGlobalHelper(name);
30
- }
40
+ removeContextHelper(name, fn);
31
41
  }
32
42
  };
33
- }, [contextHelpers]);
43
+ }, [addContextHelper, contextHelpers, removeContextHelper]);
34
44
  const getAdditionalContext = useCallback(async () => {
35
- const contexts = await resolveAdditionalContext();
45
+ const contexts = await resolveAdditionalContext(helpers);
36
46
  return contexts;
37
- }, []);
47
+ }, [helpers]);
38
48
  const getContextHelpers = useCallback(() => {
39
- return getHelpers();
40
- }, []);
41
- const addContextHelper = useCallback((name, helper) => {
42
- addHelper(name, helper);
43
- }, []);
44
- const removeContextHelper = useCallback((name) => {
45
- removeGlobalHelper(name);
46
- }, []);
49
+ return helpers;
50
+ }, [helpers]);
47
51
  const value = useMemo(() => ({
48
52
  getAdditionalContext,
49
53
  getContextHelpers,
@@ -68,10 +72,18 @@ export const useTamboContextHelpers = () => {
68
72
  return context;
69
73
  // Fallback to global registry so the API is standalone outside any provider
70
74
  return {
71
- getAdditionalContext: async () => (await resolveAdditionalContext()),
72
- getContextHelpers: () => getHelpers(),
73
- addContextHelper: (name, helper) => addHelper(name, helper),
74
- removeContextHelper: (name) => removeGlobalHelper(name),
75
+ getAdditionalContext: async () => {
76
+ throw new Error("No provider found");
77
+ },
78
+ getContextHelpers: () => {
79
+ throw new Error("No provider found");
80
+ },
81
+ addContextHelper: (_name, _helper) => {
82
+ throw new Error("No provider found");
83
+ },
84
+ removeContextHelper: (_name) => {
85
+ throw new Error("No provider found");
86
+ },
75
87
  };
76
88
  };
77
89
  //# sourceMappingURL=tambo-context-helpers-provider.js.map
@@ -1 +1 @@
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,OAAO,GACR,MAAM,OAAO,CAAC;AAMf,OAAO,EACL,SAAS,EACT,UAAU,EACV,YAAY,IAAI,kBAAkB,EAClC,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AAsBrC,MAAM,0BAA0B,GAC9B,aAAa,CAAyC,IAAI,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAE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AmB,GAAG,WAAW,CAAC,CAAC,IAAY,EAAE,EAAE;QACvD,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,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;;;;GAIG;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,4EAA4E;IAC5E,OAAO;QACL,oBAAoB,EAAE,KAAK,IAAI,EAAE,CAC/B,CAAC,MAAM,wBAAwB,EAAE,CAAwB;QAC3D,iBAAiB,EAAE,GAAG,EAAE,CAAC,UAAU,EAAoB;QACvD,gBAAgB,EAAE,CAAC,IAAY,EAAE,MAAuB,EAAE,EAAE,CAC1D,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;QACzB,mBAAmB,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;KAC7B,CAAC;AACvC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useMemo,\n} from \"react\";\nimport {\n AdditionalContext,\n ContextHelpers,\n ContextHelperFn,\n} from \"../context-helpers\";\nimport {\n addHelper,\n getHelpers,\n removeHelper as removeGlobalHelper,\n resolveAdditionalContext,\n} 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 // Hydrate the global registry with initial helpers (runs on prop changes)\n React.useEffect(() => {\n const addedEntries: [string, ContextHelperFn][] = [];\n\n if (contextHelpers) {\n for (const [name, fn] of Object.entries(contextHelpers)) {\n addHelper(name, fn);\n addedEntries.push([name, fn]);\n }\n }\n\n return () => {\n const current = getHelpers();\n for (const [name, fn] of addedEntries) {\n // Only remove if the registry still points to the same function\n if (current[name] === fn) {\n removeGlobalHelper(name);\n }\n }\n };\n }, [contextHelpers]);\n\n const getAdditionalContext = useCallback(async () => {\n const contexts = await resolveAdditionalContext();\n return contexts as AdditionalContext[];\n }, []);\n\n const getContextHelpers = useCallback(() => {\n return getHelpers() as ContextHelpers;\n }, []);\n\n const addContextHelper = useCallback(\n (name: string, helper: ContextHelperFn) => {\n addHelper(name, helper);\n },\n [],\n );\n\n const removeContextHelper = useCallback((name: string) => {\n removeGlobalHelper(name);\n }, []);\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 (await resolveAdditionalContext()) as AdditionalContext[],\n getContextHelpers: () => getHelpers() as ContextHelpers,\n addContextHelper: (name: string, helper: ContextHelperFn) =>\n addHelper(name, helper),\n removeContextHelper: (name: string) => removeGlobalHelper(name),\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,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";\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 +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;AAEf,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAGrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4PjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,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;AAEf,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAGrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA8PjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC"}
@@ -24,94 +24,96 @@ export const TamboInteractableProvider = ({ children, }) => {
24
24
  const [interactableComponents, setInteractableComponents] = useState([]);
25
25
  const { registerTool } = useTamboComponent();
26
26
  useEffect(() => {
27
- registerTool({
28
- name: "get_all_interactable_components",
29
- description: "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.",
30
- tool: () => {
31
- return {
32
- components: interactableComponents,
33
- };
34
- },
35
- toolSchema: z.function().returns(z.object({
36
- components: z.array(z.object({
37
- id: z.string(),
38
- componentName: z.string(),
39
- props: z.record(z.any()),
40
- propsSchema: z.object({}).optional(),
27
+ if (interactableComponents.length > 0) {
28
+ registerTool({
29
+ name: "get_all_interactable_components",
30
+ description: "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.",
31
+ tool: () => {
32
+ return {
33
+ components: interactableComponents,
34
+ };
35
+ },
36
+ toolSchema: z.function().returns(z.object({
37
+ components: z.array(z.object({
38
+ id: z.string(),
39
+ componentName: z.string(),
40
+ props: z.record(z.any()),
41
+ propsSchema: z.object({}).optional(),
42
+ })),
41
43
  })),
42
- })),
43
- });
44
- registerTool({
45
- name: "get_interactable_component_by_id",
46
- description: "Get a specific interactable component by its ID",
47
- tool: (componentId) => {
48
- const component = interactableComponents.find((c) => c.id === componentId);
49
- if (!component) {
44
+ });
45
+ registerTool({
46
+ name: "get_interactable_component_by_id",
47
+ description: "Get a specific interactable component by its ID",
48
+ tool: (componentId) => {
49
+ const component = interactableComponents.find((c) => c.id === componentId);
50
+ if (!component) {
51
+ return {
52
+ success: false,
53
+ error: `Component with ID ${componentId} not found`,
54
+ };
55
+ }
50
56
  return {
51
- success: false,
52
- error: `Component with ID ${componentId} not found`,
57
+ success: true,
58
+ component: {
59
+ id: component.id,
60
+ componentName: component.name,
61
+ props: component.props,
62
+ },
53
63
  };
54
- }
55
- return {
56
- success: true,
57
- component: {
58
- id: component.id,
59
- componentName: component.name,
60
- props: component.props,
61
- },
62
- };
63
- },
64
- toolSchema: z
65
- .function()
66
- .args(z.string())
67
- .returns(z.object({
68
- success: z.boolean(),
69
- component: z
70
- .object({
71
- id: z.string(),
72
- componentName: z.string(),
73
- props: z.record(z.any()),
74
- })
75
- .optional(),
76
- error: z.string().optional(),
77
- })),
78
- });
79
- registerTool({
80
- name: "remove_interactable_component",
81
- description: "Remove an interactable component from the system",
82
- tool: (componentId) => {
83
- const component = interactableComponents.find((c) => c.id === componentId);
84
- if (!component) {
64
+ },
65
+ toolSchema: z
66
+ .function()
67
+ .args(z.string())
68
+ .returns(z.object({
69
+ success: z.boolean(),
70
+ component: z
71
+ .object({
72
+ id: z.string(),
73
+ componentName: z.string(),
74
+ props: z.record(z.any()),
75
+ })
76
+ .optional(),
77
+ error: z.string().optional(),
78
+ })),
79
+ });
80
+ registerTool({
81
+ name: "remove_interactable_component",
82
+ description: "Remove an interactable component from the system",
83
+ tool: (componentId) => {
84
+ const component = interactableComponents.find((c) => c.id === componentId);
85
+ if (!component) {
86
+ return {
87
+ success: false,
88
+ error: `Component with ID ${componentId} not found`,
89
+ };
90
+ }
91
+ setInteractableComponents((prev) => prev.filter((c) => c.id !== componentId));
85
92
  return {
86
- success: false,
87
- error: `Component with ID ${componentId} not found`,
93
+ success: true,
94
+ componentId,
95
+ removedComponent: {
96
+ id: component.id,
97
+ componentName: component.name,
98
+ props: component.props,
99
+ },
88
100
  };
89
- }
90
- setInteractableComponents((prev) => prev.filter((c) => c.id !== componentId));
91
- return {
92
- success: true,
93
- componentId,
94
- removedComponent: {
95
- id: component.id,
96
- componentName: component.name,
97
- props: component.props,
98
- },
99
- };
100
- },
101
- toolSchema: z
102
- .function()
103
- .args(z.string())
104
- .returns(z.object({
105
- success: z.boolean(),
106
- componentId: z.string(),
107
- removedComponent: z.object({
108
- id: z.string(),
109
- componentName: z.string(),
110
- props: z.record(z.any()),
111
- }),
112
- error: z.string().optional(),
113
- })),
114
- });
101
+ },
102
+ toolSchema: z
103
+ .function()
104
+ .args(z.string())
105
+ .returns(z.object({
106
+ success: z.boolean(),
107
+ componentId: z.string(),
108
+ removedComponent: z.object({
109
+ id: z.string(),
110
+ componentName: z.string(),
111
+ props: z.record(z.any()),
112
+ }),
113
+ error: z.string().optional(),
114
+ })),
115
+ });
116
+ }
115
117
  }, [interactableComponents, registerTool]);
116
118
  const updateInteractableComponentProps = useCallback((id, newProps) => {
117
119
  let updateResult = "Updated successfully";
@@ -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;AAKxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,wBAAwB,GAAG,aAAa,CAA2B;IACvE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C,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAC9C,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 {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-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\n useEffect(() => {\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 }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>) => {\n let updateResult = \"Updated successfully\";\n\n setInteractableComponents((prev) => {\n const componentExists = prev.some((c) => c.id === id);\n\n if (!componentExists) {\n updateResult = `Error: Component with ID ${id} not found`;\n return prev;\n }\n\n const updatedComponents = prev.map((c) =>\n c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c,\n );\n\n // Check if the update actually changed anything\n const originalComponent = prev.find((c) => c.id === id);\n const updatedComponent = updatedComponents.find((c) => c.id === id);\n\n if (!originalComponent || !updatedComponent) {\n updateResult = `Error: Failed to update component with ID ${id}`;\n return prev;\n }\n\n // Check if props actually changed\n const propsChanged =\n JSON.stringify(originalComponent.props) !==\n JSON.stringify(updatedComponent.props);\n\n if (!propsChanged) {\n updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;\n return prev;\n }\n\n return updatedComponents;\n });\n\n return updateResult;\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 ? component.propsSchema\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})`,\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 new props to update the component with\",\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).substr(2, 9)}`;\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"]}
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;AAKxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,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,GAAE,CAAC;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;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,YAAY,CAAC;gBAC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QACb,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC,EACD,CAAC,sBAAsB,CAAC,CACzB,CAAC;IAEF,MAAM,+BAA+B,GAAG,WAAW,CACjD,CAAC,aAAqB,EAAE,EAAE;QACxB,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;IACxE,CAAC,EACD,CAAC,sBAAsB,CAAC,CACzB,CAAC;IAEF,MAAM,8BAA8B,GAAG,WAAW,CAAC,GAAG,EAAE;QACtD,yBAAyB,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAA6B;QACtC,sBAAsB;QACtB,wBAAwB;QACxB,2BAA2B;QAC3B,gCAAgC;QAChC,wBAAwB;QACxB,+BAA+B;QAC/B,8BAA8B;KAC/B,CAAC;IAEF,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAC9C,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 {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-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\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>) => {\n let updateResult = \"Updated successfully\";\n\n setInteractableComponents((prev) => {\n const componentExists = prev.some((c) => c.id === id);\n\n if (!componentExists) {\n updateResult = `Error: Component with ID ${id} not found`;\n return prev;\n }\n\n const updatedComponents = prev.map((c) =>\n c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c,\n );\n\n // Check if the update actually changed anything\n const originalComponent = prev.find((c) => c.id === id);\n const updatedComponent = updatedComponents.find((c) => c.id === id);\n\n if (!originalComponent || !updatedComponent) {\n updateResult = `Error: Failed to update component with ID ${id}`;\n return prev;\n }\n\n // Check if props actually changed\n const propsChanged =\n JSON.stringify(originalComponent.props) !==\n JSON.stringify(updatedComponent.props);\n\n if (!propsChanged) {\n updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;\n return prev;\n }\n\n return updatedComponents;\n });\n\n return updateResult;\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 ? component.propsSchema\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})`,\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 new props to update the component with\",\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).substr(2, 9)}`;\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.46.4",
3
+ "version": "0.47.0",
4
4
  "description": "React client package for Tambo AI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -94,8 +94,8 @@
94
94
  "eslint-plugin-jsdoc": "^54.1.1",
95
95
  "eslint-plugin-react": "^7.37.5",
96
96
  "eslint-plugin-react-hooks": "^5.1.0",
97
- "jest": "^30.0.5",
98
- "jest-environment-jsdom": "^30.0.5",
97
+ "jest": "^30.1.1",
98
+ "jest-environment-jsdom": "^30.1.1",
99
99
  "lint-staged": "^16.1.5",
100
100
  "prettier": "^3.6.2",
101
101
  "prettier-2": "npm:prettier@^2",