@tambo-ai/react 0.46.5 → 0.48.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 (97) 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/current-interactables-context-helper.d.ts +28 -0
  4. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -0
  5. package/dist/context-helpers/current-interactables-context-helper.js +61 -0
  6. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -0
  7. package/dist/context-helpers/index.d.ts +1 -0
  8. package/dist/context-helpers/index.d.ts.map +1 -1
  9. package/dist/context-helpers/index.js +1 -0
  10. package/dist/context-helpers/index.js.map +1 -1
  11. package/dist/context-helpers/registry.d.ts +1 -22
  12. package/dist/context-helpers/registry.d.ts.map +1 -1
  13. package/dist/context-helpers/registry.js +1 -35
  14. package/dist/context-helpers/registry.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/mcp/__tests__/tambo-mcp-provider.test.d.ts +2 -0
  20. package/dist/mcp/__tests__/tambo-mcp-provider.test.d.ts.map +1 -0
  21. package/dist/mcp/__tests__/tambo-mcp-provider.test.js +115 -0
  22. package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -0
  23. package/dist/mcp/tambo-mcp-provider.d.ts +6 -0
  24. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  25. package/dist/mcp/tambo-mcp-provider.js +25 -2
  26. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  27. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
  28. package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  29. package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts +2 -0
  30. package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts.map +1 -0
  31. package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js +339 -0
  32. package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js.map +1 -0
  33. package/dist/providers/__tests__/tambo-interactables-additional-context.test.d.ts +2 -0
  34. package/dist/providers/__tests__/tambo-interactables-additional-context.test.d.ts.map +1 -0
  35. package/dist/providers/__tests__/tambo-interactables-additional-context.test.js +299 -0
  36. package/dist/providers/__tests__/tambo-interactables-additional-context.test.js.map +1 -0
  37. package/dist/providers/tambo-context-helpers-provider.d.ts +1 -1
  38. package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  39. package/dist/providers/tambo-context-helpers-provider.js +33 -21
  40. package/dist/providers/tambo-context-helpers-provider.js.map +1 -1
  41. package/dist/providers/tambo-interactable-provider.d.ts +20 -0
  42. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  43. package/dist/providers/tambo-interactable-provider.js +117 -85
  44. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  45. package/esm/context-helpers/__tests__/context-helpers-provider.test.js +10 -6
  46. package/esm/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -1
  47. package/esm/context-helpers/current-interactables-context-helper.d.ts +28 -0
  48. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -0
  49. package/esm/context-helpers/current-interactables-context-helper.js +56 -0
  50. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -0
  51. package/esm/context-helpers/index.d.ts +1 -0
  52. package/esm/context-helpers/index.d.ts.map +1 -1
  53. package/esm/context-helpers/index.js +1 -0
  54. package/esm/context-helpers/index.js.map +1 -1
  55. package/esm/context-helpers/registry.d.ts +1 -22
  56. package/esm/context-helpers/registry.d.ts.map +1 -1
  57. package/esm/context-helpers/registry.js +1 -31
  58. package/esm/context-helpers/registry.js.map +1 -1
  59. package/esm/index.d.ts +1 -1
  60. package/esm/index.d.ts.map +1 -1
  61. package/esm/index.js +1 -1
  62. package/esm/index.js.map +1 -1
  63. package/esm/mcp/__tests__/tambo-mcp-provider.test.d.ts +2 -0
  64. package/esm/mcp/__tests__/tambo-mcp-provider.test.d.ts.map +1 -0
  65. package/esm/mcp/__tests__/tambo-mcp-provider.test.js +113 -0
  66. package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -0
  67. package/esm/mcp/tambo-mcp-provider.d.ts +6 -0
  68. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  69. package/esm/mcp/tambo-mcp-provider.js +24 -2
  70. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  71. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
  72. package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
  73. package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts +2 -0
  74. package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts.map +1 -0
  75. package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js +334 -0
  76. package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js.map +1 -0
  77. package/esm/providers/__tests__/tambo-interactables-additional-context.test.d.ts +2 -0
  78. package/esm/providers/__tests__/tambo-interactables-additional-context.test.d.ts.map +1 -0
  79. package/esm/providers/__tests__/tambo-interactables-additional-context.test.js +294 -0
  80. package/esm/providers/__tests__/tambo-interactables-additional-context.test.js.map +1 -0
  81. package/esm/providers/tambo-context-helpers-provider.d.ts +1 -1
  82. package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
  83. package/esm/providers/tambo-context-helpers-provider.js +35 -23
  84. package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
  85. package/esm/providers/tambo-interactable-provider.d.ts +20 -0
  86. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  87. package/esm/providers/tambo-interactable-provider.js +115 -84
  88. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  89. package/package.json +8 -8
  90. package/dist/mcp/mcp-tools-client.d.ts +0 -96
  91. package/dist/mcp/mcp-tools-client.d.ts.map +0 -1
  92. package/dist/mcp/mcp-tools-client.js +0 -178
  93. package/dist/mcp/mcp-tools-client.js.map +0 -1
  94. package/esm/mcp/mcp-tools-client.d.ts +0 -96
  95. package/esm/mcp/mcp-tools-client.d.ts.map +0 -1
  96. package/esm/mcp/mcp-tools-client.js +0 -174
  97. package/esm/mcp/mcp-tools-client.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":";;;AAAA,iCAAsC;AAEtC,kFAAwE;AACxE,6CAAuD;AASvD;;;GAGG;AACI,MAAM,gBAAgB,GAGxB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAChC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,0CAAgB,GAAE,CAAC;IAE5C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QACD,KAAK,UAAU,kBAAkB,CAAC,UAAsC;YACtE,yDAAyD;YACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;YAClD,MAAM,eAAe,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;gBACzD,MAAM,MAAM,GACV,OAAO,SAAS,KAAK,QAAQ;oBAC3B,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,yBAAY,CAAC,GAAG,EAAE;oBACjD,CAAC,CAAC,SAAS,CAAC;gBAChB,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,yBAAY,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;gBACpE,MAAM,SAAS,GAAG,MAAM,sBAAS,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;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4BACf,sBAAsB;4BACtB,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;wBAChE,CAAC;wBACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBACzD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;4BACnB,8CAA8C;4BAC9C,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;wBACvC,CAAC;wBACD,OAAO,MAAM,CAAC,OAAO,CAAC;oBACxB,CAAC;oBACD,UAAU,EAAE,IAAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AArEW,QAAA,gBAAgB,oBAqE3B","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { MCPClient, MCPTransport } from \"./mcp-client\";\n\nexport interface McpServerInfo {\n name?: string;\n url: string;\n description?: string;\n transport?: MCPTransport;\n customHeaders?: Record<string, string>;\n}\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: (McpServerInfo | string)[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: (McpServerInfo | string)[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const server =\n typeof mcpServer === \"string\"\n ? { url: mcpServer, transport: MCPTransport.SSE }\n : mcpServer;\n const { url, transport = MCPTransport.SSE, customHeaders } = server;\n const mcpClient = await MCPClient.create(url, transport, customHeaders);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
1
+ {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":";;;AAUA,kDAsBC;AAhCD,iCAAsC;AAEtC,kFAAwE;AACxE,6CAAuD;AAEvD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,OAAgB;IAClD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,OAAO;aACtB,MAAM,CACL,CAAC,IAAI,EA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CAAC,CAAC;wBAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;4BACf,sBAAsB;4BACtB,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;wBAChE,CAAC;wBACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBACzD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;4BACnB,MAAM,YAAY,GAAG,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;4BACzD,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;wBAChC,CAAC;wBACD,OAAO,MAAM,CAAC,OAAO,CAAC;oBACxB,CAAC;oBACD,UAAU,EAAE,IAAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AArEW,QAAA,gBAAgB,oBAqE3B","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { MCPClient, MCPTransport } from \"./mcp-client\";\n\n/**\n * Extracts error message from MCP tool result content.\n * Handles both array and string content formats.\n * Always returns a string, even for invalid/null inputs.\n */\nexport function extractErrorMessage(content: unknown): string {\n if (content === undefined || content === null) {\n return \"Unknown error occurred\";\n }\n\n if (Array.isArray(content)) {\n const textItems = content\n .filter(\n (item) => item && item.type === \"text\" && typeof item.text === \"string\",\n )\n .map((item) => item.text);\n\n return textItems.length > 0\n ? textItems.join(\" \")\n : \"Error occurred but no details provided\";\n }\n\n if (typeof content === \"object\") {\n return JSON.stringify(content);\n }\n\n return `${content}`;\n}\n\nexport interface McpServerInfo {\n name?: string;\n url: string;\n description?: string;\n transport?: MCPTransport;\n customHeaders?: Record<string, string>;\n}\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: (McpServerInfo | string)[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: (McpServerInfo | string)[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const server =\n typeof mcpServer === \"string\"\n ? { url: mcpServer, transport: MCPTransport.SSE }\n : mcpServer;\n const { url, transport = MCPTransport.SSE, customHeaders } = server;\n const mcpClient = await MCPClient.create(url, transport, customHeaders);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n const errorMessage = extractErrorMessage(result.content);\n throw new Error(errorMessage);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = require("@testing-library/react");
7
7
  const react_2 = __importDefault(require("react"));
8
8
  const context_helpers_1 = require("../../context-helpers");
9
- const registry_1 = require("../../context-helpers/registry");
10
9
  const tambo_context_helpers_provider_1 = require("../tambo-context-helpers-provider");
11
10
  /**
12
11
  * Test suite for TamboContextHelpersProvider (simplified API, registry-backed)
@@ -23,43 +22,11 @@ const tambo_context_helpers_provider_1 = require("../tambo-context-helpers-provi
23
22
  describe("TamboContextHelpersProvider", () => {
24
23
  // Ensure registry is clean for each test to avoid cross-test contamination
25
24
  beforeEach(() => {
26
- (0, registry_1.setHelpers)({});
27
25
  jest.clearAllMocks();
28
26
  });
29
27
  // Base wrapper with no helpers provided
30
28
  const wrapper = ({ children }) => (react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, null, children));
31
29
  describe("useTamboContextHelpers", () => {
32
- /**
33
- * NOTE: The hook is registry-backed and safe outside provider. It should not throw.
34
- * This replaces the previous behavior that threw without a provider.
35
- */
36
- it("should be safe outside provider (registry-backed no provider)", async () => {
37
- const consoleSpy = jest
38
- .spyOn(console, "error")
39
- .mockImplementation(() => { });
40
- const { result } = (0, react_1.renderHook)(() => (0, tambo_context_helpers_provider_1.useTamboContextHelpers)());
41
- // Should return callable functions
42
- expect(typeof result.current.getAdditionalContext).toBe("function");
43
- expect(typeof result.current.getContextHelpers).toBe("function");
44
- expect(typeof result.current.addContextHelper).toBe("function");
45
- expect(typeof result.current.removeContextHelper).toBe("function");
46
- // Starts empty
47
- expect(await result.current.getAdditionalContext()).toHaveLength(0);
48
- // Add a helper and verify
49
- (0, react_1.act)(() => {
50
- result.current.addContextHelper("outsideHelper", () => ({ ok: true }));
51
- });
52
- const contexts = await result.current.getAdditionalContext();
53
- expect(contexts).toContainEqual({
54
- name: "outsideHelper",
55
- context: { ok: true },
56
- });
57
- // Cleanup
58
- (0, react_1.act)(() => {
59
- result.current.removeContextHelper("outsideHelper");
60
- });
61
- consoleSpy.mockRestore();
62
- });
63
30
  /**
64
31
  * Verifies that the hook returns the expected API functions when used within a provider.
65
32
  */
@@ -134,7 +101,6 @@ describe("TamboContextHelpersProvider", () => {
134
101
  */
135
102
  describe("Custom Context Helpers via contextHelpers config", () => {
136
103
  beforeEach(() => {
137
- (0, registry_1.setHelpers)({});
138
104
  jest.clearAllMocks();
139
105
  });
140
106
  /**
@@ -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,kDAAyD;AACzD,kDAA0B;AAC1B,2DAG+B;AAC/B,6DAA4D;AAC5D,sFAG2C;AAE3C;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,2EAA2E;IAC3E,UAAU,CAAC,GAAG,EAAE;QACd,IAAA,qBAAU,EAAC,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,8BAAC,4DAA2B,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,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,uDAAsB,GAAE,CAAC,CAAC;YAE9D,mCAAmC;YACnC,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,CAA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gB,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 { 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,kDAAyD;AACzD,kDAA0B;AAC1B,2DAG+B;AAC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,IAC1B,cAAc,EAAE;oBACd,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;iBAC7C,IAEA,QAAQ,CACmB,CAC/B;SACF,CAAC,CAAC;QAEH,yBAAyB;QACzB,IAAI,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAC3D,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC;YAC9B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5B,CAAC,CAAC;QAEH,oBAAoB;QACpB,IAAA,WAAG,EAAC,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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tambo-interactables-additional-context-edge-cases.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactables-additional-context-edge-cases.test.d.ts","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = require("@testing-library/react");
7
+ const react_2 = __importDefault(require("react"));
8
+ const zod_1 = require("zod");
9
+ const tambo_context_helpers_provider_1 = require("../tambo-context-helpers-provider");
10
+ const tambo_interactable_provider_1 = require("../tambo-interactable-provider");
11
+ const tambo_stubs_1 = require("../tambo-stubs");
12
+ const with_tambo_interactable_1 = require("../hoc/with-tambo-interactable");
13
+ function wrapperWithProviders(children) {
14
+ const thread = {
15
+ id: "t-1",
16
+ projectId: "p-1",
17
+ createdAt: new Date().toISOString(),
18
+ updatedAt: new Date().toISOString(),
19
+ messages: [],
20
+ metadata: {},
21
+ };
22
+ return (react_2.default.createElement(tambo_stubs_1.TamboStubProvider, { thread: thread, registerTool: () => { }, registerTools: () => { }, registerComponent: () => { }, addToolAssociation: () => { } },
23
+ react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, null, children)));
24
+ }
25
+ describe("Interactables AdditionalContext - Edge Cases & Advanced Scenarios", () => {
26
+ test("handles components without propsSchema gracefully", async () => {
27
+ const SimpleComponent = ({ text }) => (react_2.default.createElement("div", null, text));
28
+ const InteractableSimpleComponent = (0, with_tambo_interactable_1.withTamboInteractable)(SimpleComponent, {
29
+ componentName: "SimpleComponent",
30
+ description: "A component without schema",
31
+ // No propsSchema provided
32
+ });
33
+ let capturedContexts = [];
34
+ const TestComponent = () => {
35
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
36
+ react_2.default.useEffect(() => {
37
+ let mounted = true;
38
+ getAdditionalContext().then((contexts) => {
39
+ if (mounted) {
40
+ capturedContexts = contexts;
41
+ }
42
+ });
43
+ return () => {
44
+ mounted = false;
45
+ };
46
+ }, [getAdditionalContext]);
47
+ return react_2.default.createElement("div", { "data-testid": "ready" }, "ready");
48
+ };
49
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
50
+ react_2.default.createElement(InteractableSimpleComponent, { text: "test" }),
51
+ react_2.default.createElement(TestComponent, null))));
52
+ await (0, react_1.waitFor)(() => {
53
+ expect(getByTestId("ready")).toBeInTheDocument();
54
+ const entry = capturedContexts.find((c) => c.name === "interactables");
55
+ expect(entry).toBeDefined();
56
+ const component = entry.context.components[0];
57
+ expect(component.propsSchema).toBe("Not specified");
58
+ });
59
+ });
60
+ test("handles component unmounting and remounting correctly", async () => {
61
+ const Note = ({ title }) => react_2.default.createElement("div", null, title);
62
+ const InteractableNote = (0, with_tambo_interactable_1.withTamboInteractable)(Note, {
63
+ componentName: "Note",
64
+ description: "A note",
65
+ propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
66
+ });
67
+ let capturedContexts = [];
68
+ const TestComponent = () => {
69
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
70
+ react_2.default.useEffect(() => {
71
+ let mounted = true;
72
+ const interval = setInterval(() => {
73
+ getAdditionalContext().then((contexts) => {
74
+ if (mounted) {
75
+ capturedContexts = contexts;
76
+ }
77
+ });
78
+ }, 50);
79
+ return () => {
80
+ mounted = false;
81
+ clearInterval(interval);
82
+ };
83
+ }, [getAdditionalContext]);
84
+ return react_2.default.createElement("div", { "data-testid": "ready" }, "ready");
85
+ };
86
+ const Host = () => {
87
+ const [showNote, setShowNote] = react_2.default.useState(true);
88
+ react_2.default.useEffect(() => {
89
+ // Toggle the note on/off to test unmounting
90
+ const timeout = setTimeout(() => setShowNote(false), 100);
91
+ const timeout2 = setTimeout(() => setShowNote(true), 200);
92
+ return () => {
93
+ clearTimeout(timeout);
94
+ clearTimeout(timeout2);
95
+ };
96
+ }, []);
97
+ return (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
98
+ showNote && react_2.default.createElement(InteractableNote, { title: "dynamic note" }),
99
+ react_2.default.createElement(TestComponent, null)));
100
+ };
101
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(Host, null)));
102
+ await (0, react_1.waitFor)(() => {
103
+ expect(getByTestId("ready")).toBeInTheDocument();
104
+ }, { timeout: 1000 });
105
+ // Eventually should show the note again
106
+ await (0, react_1.waitFor)(() => {
107
+ const entry = capturedContexts.find((c) => c.name === "interactables");
108
+ expect(entry?.context?.components).toHaveLength(1);
109
+ }, { timeout: 1000 });
110
+ });
111
+ test("context helper updates when props change from parent", async () => {
112
+ const Counter = ({ count, label = "Count", }) => (react_2.default.createElement("div", null,
113
+ label,
114
+ ": ",
115
+ count));
116
+ const InteractableCounter = (0, with_tambo_interactable_1.withTamboInteractable)(Counter, {
117
+ componentName: "Counter",
118
+ description: "A counter component",
119
+ propsSchema: zod_1.z.object({
120
+ count: zod_1.z.number(),
121
+ label: zod_1.z.string().optional(),
122
+ }),
123
+ });
124
+ let capturedContexts = [];
125
+ const TestComponent = () => {
126
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
127
+ react_2.default.useEffect(() => {
128
+ let mounted = true;
129
+ const interval = setInterval(() => {
130
+ getAdditionalContext().then((contexts) => {
131
+ if (mounted) {
132
+ capturedContexts = contexts;
133
+ }
134
+ });
135
+ }, 50);
136
+ return () => {
137
+ mounted = false;
138
+ clearInterval(interval);
139
+ };
140
+ }, [getAdditionalContext]);
141
+ return react_2.default.createElement("div", { "data-testid": "ready" }, "ready");
142
+ };
143
+ const Host = () => {
144
+ const [count, setCount] = react_2.default.useState(0);
145
+ const [label, setLabel] = react_2.default.useState("Items");
146
+ react_2.default.useEffect(() => {
147
+ const timeout1 = setTimeout(() => setCount(5), 100);
148
+ const timeout2 = setTimeout(() => setLabel("Updated Items"), 200);
149
+ return () => {
150
+ clearTimeout(timeout1);
151
+ clearTimeout(timeout2);
152
+ };
153
+ }, []);
154
+ return (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
155
+ react_2.default.createElement(InteractableCounter, { count: count, label: label }),
156
+ react_2.default.createElement(TestComponent, null)));
157
+ };
158
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(Host, null)));
159
+ await (0, react_1.waitFor)(() => {
160
+ expect(getByTestId("ready")).toBeInTheDocument();
161
+ });
162
+ // Wait for updates to propagate
163
+ await (0, react_1.waitFor)(() => {
164
+ const entry = capturedContexts.find((c) => c.name === "interactables");
165
+ if (entry?.context?.components?.[0]) {
166
+ const props = entry.context.components[0].props;
167
+ expect(props.count).toBe(5);
168
+ expect(props.label).toBe("Updated Items");
169
+ }
170
+ }, { timeout: 1000 });
171
+ });
172
+ test("multiple providers with nested context helpers work correctly", async () => {
173
+ const Note = ({ title }) => react_2.default.createElement("div", null, title);
174
+ const InteractableNote = (0, with_tambo_interactable_1.withTamboInteractable)(Note, {
175
+ componentName: "Note",
176
+ description: "A note",
177
+ propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
178
+ });
179
+ let outerContexts = [];
180
+ let innerContexts = [];
181
+ const OuterTestComponent = () => {
182
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
183
+ react_2.default.useEffect(() => {
184
+ let mounted = true;
185
+ getAdditionalContext().then((contexts) => {
186
+ if (mounted) {
187
+ outerContexts = contexts;
188
+ }
189
+ });
190
+ return () => {
191
+ mounted = false;
192
+ };
193
+ }, [getAdditionalContext]);
194
+ return react_2.default.createElement("div", { "data-testid": "outer-ready" }, "outer ready");
195
+ };
196
+ const InnerTestComponent = () => {
197
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
198
+ react_2.default.useEffect(() => {
199
+ let mounted = true;
200
+ getAdditionalContext().then((contexts) => {
201
+ if (mounted) {
202
+ innerContexts = contexts;
203
+ }
204
+ });
205
+ return () => {
206
+ mounted = false;
207
+ };
208
+ }, [getAdditionalContext]);
209
+ return react_2.default.createElement("div", { "data-testid": "inner-ready" }, "inner ready");
210
+ };
211
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
212
+ react_2.default.createElement(InteractableNote, { title: "outer note" }),
213
+ react_2.default.createElement(OuterTestComponent, null),
214
+ react_2.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, { contextHelpers: {
215
+ customContext: () => ({ custom: "inner" }),
216
+ } },
217
+ react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
218
+ react_2.default.createElement(InteractableNote, { title: "inner note" }),
219
+ react_2.default.createElement(InnerTestComponent, null))))));
220
+ await (0, react_1.waitFor)(() => {
221
+ expect(getByTestId("outer-ready")).toBeInTheDocument();
222
+ expect(getByTestId("inner-ready")).toBeInTheDocument();
223
+ });
224
+ await (0, react_1.waitFor)(() => {
225
+ // Outer context should have outer note
226
+ const outerEntry = outerContexts.find((c) => c.name === "interactables");
227
+ expect(outerEntry?.context?.components).toHaveLength(1);
228
+ expect(outerEntry?.context?.components[0]?.props?.title).toBe("outer note");
229
+ // Inner context should have inner note and custom context
230
+ const innerEntry = innerContexts.find((c) => c.name === "interactables");
231
+ expect(innerEntry?.context?.components).toHaveLength(1);
232
+ expect(innerEntry?.context?.components[0]?.props?.title).toBe("inner note");
233
+ const customEntry = innerContexts.find((c) => c.name === "customContext");
234
+ expect(customEntry?.context).toEqual({ custom: "inner" });
235
+ });
236
+ });
237
+ test("provider cleanup removes helper when last provider unmounts", async () => {
238
+ const Note = ({ title }) => react_2.default.createElement("div", null, title);
239
+ const InteractableNote = (0, with_tambo_interactable_1.withTamboInteractable)(Note, {
240
+ componentName: "Note",
241
+ description: "A note",
242
+ propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
243
+ });
244
+ let capturedContexts = [];
245
+ const TestComponent = () => {
246
+ const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
247
+ react_2.default.useEffect(() => {
248
+ let mounted = true;
249
+ const interval = setInterval(() => {
250
+ getAdditionalContext().then((contexts) => {
251
+ if (mounted) {
252
+ capturedContexts = contexts;
253
+ }
254
+ });
255
+ }, 50);
256
+ return () => {
257
+ mounted = false;
258
+ clearInterval(interval);
259
+ };
260
+ }, [getAdditionalContext]);
261
+ return react_2.default.createElement("div", { "data-testid": "ready" }, "ready");
262
+ };
263
+ const Host = () => {
264
+ const [showProvider, setShowProvider] = react_2.default.useState(true);
265
+ react_2.default.useEffect(() => {
266
+ const timeout = setTimeout(() => setShowProvider(false), 200);
267
+ return () => clearTimeout(timeout);
268
+ }, []);
269
+ return (react_2.default.createElement(react_2.default.Fragment, null,
270
+ showProvider && (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
271
+ react_2.default.createElement(InteractableNote, { title: "will disappear" }))),
272
+ react_2.default.createElement(TestComponent, null)));
273
+ };
274
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(Host, null)));
275
+ // Initially should have the context
276
+ await (0, react_1.waitFor)(() => {
277
+ expect(getByTestId("ready")).toBeInTheDocument();
278
+ const entry = capturedContexts.find((c) => c.name === "interactables");
279
+ expect(entry).toBeDefined();
280
+ });
281
+ // After provider unmounts, context should be gone
282
+ await (0, react_1.waitFor)(() => {
283
+ const entry = capturedContexts.find((c) => c.name === "interactables");
284
+ expect(entry).toBeUndefined();
285
+ }, { timeout: 1000 });
286
+ });
287
+ test("helper error handling doesn't crash the system", async () => {
288
+ const Note = ({ title }) => react_2.default.createElement("div", null, title);
289
+ const InteractableNote = (0, with_tambo_interactable_1.withTamboInteractable)(Note, {
290
+ componentName: "Note",
291
+ description: "A note",
292
+ propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
293
+ });
294
+ // Mock console.error to capture error logs
295
+ const consoleSpy = jest
296
+ .spyOn(console, "error")
297
+ .mockImplementation(() => { });
298
+ let capturedContexts = [];
299
+ const TestComponent = () => {
300
+ const { getAdditionalContext, addContextHelper } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
301
+ react_2.default.useEffect(() => {
302
+ // Add a helper that throws an error
303
+ addContextHelper("errorHelper", () => {
304
+ throw new Error("Test error in helper");
305
+ });
306
+ }, [addContextHelper]);
307
+ react_2.default.useEffect(() => {
308
+ let mounted = true;
309
+ getAdditionalContext()
310
+ .then((contexts) => {
311
+ if (mounted) {
312
+ capturedContexts = contexts;
313
+ }
314
+ })
315
+ .catch(() => {
316
+ // Should not reach here - errors should be handled gracefully
317
+ });
318
+ return () => {
319
+ mounted = false;
320
+ };
321
+ }, [getAdditionalContext]);
322
+ return react_2.default.createElement("div", { "data-testid": "ready" }, "ready");
323
+ };
324
+ const { getByTestId } = (0, react_1.render)(wrapperWithProviders(react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
325
+ react_2.default.createElement(InteractableNote, { title: "test" }),
326
+ react_2.default.createElement(TestComponent, null))));
327
+ await (0, react_1.waitFor)(() => {
328
+ expect(getByTestId("ready")).toBeInTheDocument();
329
+ // Should still have the interactables context despite the error
330
+ const entry = capturedContexts.find((c) => c.name === "interactables");
331
+ expect(entry).toBeDefined();
332
+ // Error helper should not be present (filtered out)
333
+ const errorEntry = capturedContexts.find((c) => c.name === "errorHelper");
334
+ expect(errorEntry).toBeUndefined();
335
+ });
336
+ consoleSpy.mockRestore();
337
+ });
338
+ });
339
+ //# sourceMappingURL=tambo-interactables-additional-context-edge-cases.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactables-additional-context-edge-cases.test.js","sourceRoot":"","sources":["../../../src/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.tsx"],"names":[],"mappings":";;;;;AAAA,kDAAyD;AACzD,kDAA0B;AAC1B,6BAAwB;AACxB,sFAG2C;AAC3C,gFAA2E;AAC3E,gDAAmD;AACnD,4EAAuE;AAEvE,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,MAAM,GAAG;QACb,EAAE,EAAE,KAAK;QACT,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;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aAAa,CACrC,CAAC;YACF,MAAM,CAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { render, waitFor } from \"@testing-library/react\";\nimport React from \"react\";\nimport { z } from \"zod\";\nimport {\n useTamboContextHelpers,\n TamboContextHelpersProvider,\n} from \"../tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"../tambo-interactable-provider\";\nimport { TamboStubProvider } from \"../tambo-stubs\";\nimport { withTamboInteractable } from \"../hoc/with-tambo-interactable\";\n\nfunction wrapperWithProviders(children: React.ReactNode) {\n const thread = {\n id: \"t-1\",\n projectId: \"p-1\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n messages: [],\n metadata: {},\n } as any;\n\n return (\n <TamboStubProvider\n thread={thread}\n registerTool={() => {}}\n registerTools={() => {}}\n registerComponent={() => {}}\n addToolAssociation={() => {}}\n >\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n </TamboStubProvider>\n );\n}\n\ndescribe(\"Interactables AdditionalContext - Edge Cases & Advanced Scenarios\", () => {\n test(\"handles components without propsSchema gracefully\", async () => {\n const SimpleComponent: React.FC<{ text: string }> = ({ text }) => (\n <div>{text}</div>\n );\n\n const InteractableSimpleComponent = withTamboInteractable(SimpleComponent, {\n componentName: \"SimpleComponent\",\n description: \"A component without schema\",\n // No propsSchema provided\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableSimpleComponent text=\"test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n const component = entry!.context.components[0];\n expect(component.propsSchema).toBe(\"Not specified\");\n });\n });\n\n test(\"handles component unmounting and remounting correctly\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n const interval = setInterval(() => {\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n }, 50);\n return () => {\n mounted = false;\n clearInterval(interval);\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const Host = () => {\n const [showNote, setShowNote] = React.useState(true);\n\n React.useEffect(() => {\n // Toggle the note on/off to test unmounting\n const timeout = setTimeout(() => setShowNote(false), 100);\n const timeout2 = setTimeout(() => setShowNote(true), 200);\n return () => {\n clearTimeout(timeout);\n clearTimeout(timeout2);\n };\n }, []);\n\n return (\n <TamboInteractableProvider>\n {showNote && <InteractableNote title=\"dynamic note\" />}\n <TestComponent />\n </TamboInteractableProvider>\n );\n };\n\n const { getByTestId } = render(wrapperWithProviders(<Host />));\n\n await waitFor(\n () => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n },\n { timeout: 1000 },\n );\n\n // Eventually should show the note again\n await waitFor(\n () => {\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry?.context?.components).toHaveLength(1);\n },\n { timeout: 1000 },\n );\n });\n\n test(\"context helper updates when props change from parent\", async () => {\n const Counter: React.FC<{ count: number; label?: string }> = ({\n count,\n label = \"Count\",\n }) => (\n <div>\n {label}: {count}\n </div>\n );\n\n const InteractableCounter = withTamboInteractable(Counter, {\n componentName: \"Counter\",\n description: \"A counter component\",\n propsSchema: z.object({\n count: z.number(),\n label: z.string().optional(),\n }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n const interval = setInterval(() => {\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n }, 50);\n return () => {\n mounted = false;\n clearInterval(interval);\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const Host = () => {\n const [count, setCount] = React.useState(0);\n const [label, setLabel] = React.useState(\"Items\");\n\n React.useEffect(() => {\n const timeout1 = setTimeout(() => setCount(5), 100);\n const timeout2 = setTimeout(() => setLabel(\"Updated Items\"), 200);\n return () => {\n clearTimeout(timeout1);\n clearTimeout(timeout2);\n };\n }, []);\n\n return (\n <TamboInteractableProvider>\n <InteractableCounter count={count} label={label} />\n <TestComponent />\n </TamboInteractableProvider>\n );\n };\n\n const { getByTestId } = render(wrapperWithProviders(<Host />));\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n });\n\n // Wait for updates to propagate\n await waitFor(\n () => {\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n if (entry?.context?.components?.[0]) {\n const props = entry.context.components[0].props;\n expect(props.count).toBe(5);\n expect(props.label).toBe(\"Updated Items\");\n }\n },\n { timeout: 1000 },\n );\n });\n\n test(\"multiple providers with nested context helpers work correctly\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let outerContexts: any[] = [];\n let innerContexts: any[] = [];\n\n const OuterTestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n outerContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"outer-ready\">outer ready</div>;\n };\n\n const InnerTestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n innerContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"inner-ready\">inner ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"outer note\" />\n <OuterTestComponent />\n <TamboContextHelpersProvider\n contextHelpers={{\n customContext: () => ({ custom: \"inner\" }),\n }}\n >\n <TamboInteractableProvider>\n <InteractableNote title=\"inner note\" />\n <InnerTestComponent />\n </TamboInteractableProvider>\n </TamboContextHelpersProvider>\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"outer-ready\")).toBeInTheDocument();\n expect(getByTestId(\"inner-ready\")).toBeInTheDocument();\n });\n\n await waitFor(() => {\n // Outer context should have outer note\n const outerEntry = outerContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(outerEntry?.context?.components).toHaveLength(1);\n expect(outerEntry?.context?.components[0]?.props?.title).toBe(\n \"outer note\",\n );\n\n // Inner context should have inner note and custom context\n const innerEntry = innerContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(innerEntry?.context?.components).toHaveLength(1);\n expect(innerEntry?.context?.components[0]?.props?.title).toBe(\n \"inner note\",\n );\n\n const customEntry = innerContexts.find(\n (c: any) => c.name === \"customContext\",\n );\n expect(customEntry?.context).toEqual({ custom: \"inner\" });\n });\n });\n\n test(\"provider cleanup removes helper when last provider unmounts\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n const interval = setInterval(() => {\n getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n }, 50);\n return () => {\n mounted = false;\n clearInterval(interval);\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const Host = () => {\n const [showProvider, setShowProvider] = React.useState(true);\n\n React.useEffect(() => {\n const timeout = setTimeout(() => setShowProvider(false), 200);\n return () => clearTimeout(timeout);\n }, []);\n\n return (\n <>\n {showProvider && (\n <TamboInteractableProvider>\n <InteractableNote title=\"will disappear\" />\n </TamboInteractableProvider>\n )}\n <TestComponent />\n </>\n );\n };\n\n const { getByTestId } = render(wrapperWithProviders(<Host />));\n\n // Initially should have the context\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n });\n\n // After provider unmounts, context should be gone\n await waitFor(\n () => {\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeUndefined();\n },\n { timeout: 1000 },\n );\n });\n\n test(\"helper error handling doesn't crash the system\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n // Mock console.error to capture error logs\n const consoleSpy = jest\n .spyOn(console, \"error\")\n .mockImplementation(() => {});\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext, addContextHelper } =\n useTamboContextHelpers();\n\n React.useEffect(() => {\n // Add a helper that throws an error\n addContextHelper(\"errorHelper\", () => {\n throw new Error(\"Test error in helper\");\n });\n }, [addContextHelper]);\n\n React.useEffect(() => {\n let mounted = true;\n getAdditionalContext()\n .then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n })\n .catch(() => {\n // Should not reach here - errors should be handled gracefully\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n // Should still have the interactables context despite the error\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n\n // Error helper should not be present (filtered out)\n const errorEntry = capturedContexts.find(\n (c: any) => c.name === \"errorHelper\",\n );\n expect(errorEntry).toBeUndefined();\n });\n\n consoleSpy.mockRestore();\n });\n});\n"]}