@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.
- package/dist/context-helpers/__tests__/context-helpers-provider.test.js +9 -5
- package/dist/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.d.ts +28 -0
- package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -0
- package/dist/context-helpers/current-interactables-context-helper.js +61 -0
- package/dist/context-helpers/current-interactables-context-helper.js.map +1 -0
- package/dist/context-helpers/index.d.ts +1 -0
- package/dist/context-helpers/index.d.ts.map +1 -1
- package/dist/context-helpers/index.js +1 -0
- package/dist/context-helpers/index.js.map +1 -1
- package/dist/context-helpers/registry.d.ts +1 -22
- package/dist/context-helpers/registry.d.ts.map +1 -1
- package/dist/context-helpers/registry.js +1 -35
- package/dist/context-helpers/registry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/__tests__/tambo-mcp-provider.test.d.ts +2 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js +115 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -0
- package/dist/mcp/tambo-mcp-provider.d.ts +6 -0
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +25 -2
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
- package/dist/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts +2 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts.map +1 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js +339 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js.map +1 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context.test.d.ts +2 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context.test.d.ts.map +1 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context.test.js +299 -0
- package/dist/providers/__tests__/tambo-interactables-additional-context.test.js.map +1 -0
- package/dist/providers/tambo-context-helpers-provider.d.ts +1 -1
- package/dist/providers/tambo-context-helpers-provider.d.ts.map +1 -1
- package/dist/providers/tambo-context-helpers-provider.js +33 -21
- package/dist/providers/tambo-context-helpers-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +20 -0
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +117 -85
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/context-helpers/__tests__/context-helpers-provider.test.js +10 -6
- package/esm/context-helpers/__tests__/context-helpers-provider.test.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +28 -0
- package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -0
- package/esm/context-helpers/current-interactables-context-helper.js +56 -0
- package/esm/context-helpers/current-interactables-context-helper.js.map +1 -0
- package/esm/context-helpers/index.d.ts +1 -0
- package/esm/context-helpers/index.d.ts.map +1 -1
- package/esm/context-helpers/index.js +1 -0
- package/esm/context-helpers/index.js.map +1 -1
- package/esm/context-helpers/registry.d.ts +1 -22
- package/esm/context-helpers/registry.d.ts.map +1 -1
- package/esm/context-helpers/registry.js +1 -31
- package/esm/context-helpers/registry.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/mcp/__tests__/tambo-mcp-provider.test.d.ts +2 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js +113 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -0
- package/esm/mcp/tambo-mcp-provider.d.ts +6 -0
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +24 -2
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.js +0 -34
- package/esm/providers/__tests__/tambo-context-helpers-provider.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts +2 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts.map +1 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js +334 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.js.map +1 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context.test.d.ts +2 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context.test.d.ts.map +1 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context.test.js +294 -0
- package/esm/providers/__tests__/tambo-interactables-additional-context.test.js.map +1 -0
- package/esm/providers/tambo-context-helpers-provider.d.ts +1 -1
- package/esm/providers/tambo-context-helpers-provider.d.ts.map +1 -1
- package/esm/providers/tambo-context-helpers-provider.js +35 -23
- package/esm/providers/tambo-context-helpers-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +20 -0
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +115 -84
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/package.json +8 -8
- package/dist/mcp/mcp-tools-client.d.ts +0 -96
- package/dist/mcp/mcp-tools-client.d.ts.map +0 -1
- package/dist/mcp/mcp-tools-client.js +0 -178
- package/dist/mcp/mcp-tools-client.js.map +0 -1
- package/esm/mcp/mcp-tools-client.d.ts +0 -96
- package/esm/mcp/mcp-tools-client.d.ts.map +0 -1
- package/esm/mcp/mcp-tools-client.js +0 -174
- package/esm/mcp/mcp-tools-client.js.map +0 -1
|
@@ -2,41 +2,11 @@
|
|
|
2
2
|
* Global context helpers registry.
|
|
3
3
|
* Consumers can add/remove helpers and resolve additional context anywhere.
|
|
4
4
|
*/
|
|
5
|
-
let helpers = {};
|
|
6
|
-
/**
|
|
7
|
-
* Get the current helpers map (by reference).
|
|
8
|
-
* @returns The current helpers map.
|
|
9
|
-
*/
|
|
10
|
-
export function getHelpers() {
|
|
11
|
-
return helpers;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Replace the entire helpers map (used for hydration/reset in tests).
|
|
15
|
-
* @param next - The new helpers map.
|
|
16
|
-
*/
|
|
17
|
-
export function setHelpers(next) {
|
|
18
|
-
helpers = next;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Add or replace a helper.
|
|
22
|
-
* @param name - The name of the helper.
|
|
23
|
-
* @param fn - The helper function.
|
|
24
|
-
*/
|
|
25
|
-
export function addHelper(name, fn) {
|
|
26
|
-
helpers[name] = fn;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Remove a helper by name.
|
|
30
|
-
* @param name - The name of the helper.
|
|
31
|
-
*/
|
|
32
|
-
export function removeHelper(name) {
|
|
33
|
-
delete helpers[name];
|
|
34
|
-
}
|
|
35
5
|
/**
|
|
36
6
|
* Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
|
|
37
7
|
* @returns The resolved additional context.
|
|
38
8
|
*/
|
|
39
|
-
export async function resolveAdditionalContext() {
|
|
9
|
+
export async function resolveAdditionalContext(helpers) {
|
|
40
10
|
const entries = Object.entries(helpers);
|
|
41
11
|
if (entries.length === 0)
|
|
42
12
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAiC;IAEjC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QAC/B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,CAAC;YACzB,IAAI,KAAK,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;YAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAqC,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Global context helpers registry.\n * Consumers can add/remove helpers and resolve additional context anywhere.\n */\n\nexport type HelperFn = () =>\n | any\n | null\n | undefined\n | Promise<any | null | undefined>;\n\n/**\n * Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.\n * @returns The resolved additional context.\n */\nexport async function resolveAdditionalContext(\n helpers: Record<string, HelperFn>,\n): Promise<{ name: string; context: any }[]> {\n const entries = Object.entries(helpers);\n if (entries.length === 0) return [];\n\n const results = await Promise.all(\n entries.map(async ([name, fn]) => {\n try {\n const value = await fn();\n if (value == null) return null;\n return { name, context: value };\n } catch (error) {\n console.error(`Error running context helper ${name}:`, error);\n return null;\n }\n }),\n );\n\n return results.filter(Boolean) as { name: string; context: any }[];\n}\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { GenerationStage, type TamboThreadMessage, } from "./model/generate-comp
|
|
|
13
13
|
export { type TamboThread } from "./model/tambo-thread";
|
|
14
14
|
export type { TamboInteractableComponent as InteractableComponent, TamboInteractableContext, } from "./model/tambo-interactable";
|
|
15
15
|
export { withTamboInteractable as withInteractable, type InteractableConfig, type WithTamboInteractableProps, } from "./providers/hoc/with-tambo-interactable";
|
|
16
|
-
export { useTamboInteractable } from "./providers/tambo-interactable-provider";
|
|
16
|
+
export { useTamboInteractable, useCurrentInteractablesSnapshot, } from "./providers/tambo-interactable-provider";
|
|
17
17
|
export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
|
|
18
18
|
export type { AdditionalContext, ContextHelperFn, ContextHelpers, } from "./context-helpers";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,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@@ -9,7 +9,7 @@ export { TamboClientProvider, TamboComponentProvider, TamboContextHelpersProvide
|
|
|
9
9
|
export { useTamboThreadList } from "./hooks/use-tambo-threads";
|
|
10
10
|
export { GenerationStage, } from "./model/generate-component-response";
|
|
11
11
|
export { withTamboInteractable as withInteractable, } from "./providers/hoc/with-tambo-interactable";
|
|
12
|
-
export { useTamboInteractable } from "./providers/tambo-interactable-provider";
|
|
12
|
+
export { useTamboInteractable, useCurrentInteractablesSnapshot, } from "./providers/tambo-interactable-provider";
|
|
13
13
|
// Context helpers exports
|
|
14
14
|
export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AAEzC,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,mBAAmB,GAOpB,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,qBAAqB,IAAI,gBAAgB,GAG1C,MAAM,yCAAyC,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AAEzC,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,mBAAmB,GAOpB,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,qBAAqB,IAAI,gBAAgB,GAG1C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,yCAAyC,CAAC;AAEjD,0BAA0B;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useTamboInteractable,\n useCurrentInteractablesSnapshot,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/tambo-mcp-provider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { extractErrorMessage } from "../tambo-mcp-provider";
|
|
2
|
+
// Mock the MCP client to avoid ES module issues
|
|
3
|
+
jest.mock("../mcp-client", () => ({
|
|
4
|
+
MCPClient: jest.fn(),
|
|
5
|
+
MCPTransport: {
|
|
6
|
+
SSE: "sse",
|
|
7
|
+
HTTP: "http",
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
// Mock the registry provider to avoid dependency issues
|
|
11
|
+
jest.mock("../../providers/tambo-registry-provider", () => ({
|
|
12
|
+
useTamboRegistry: jest.fn(),
|
|
13
|
+
}));
|
|
14
|
+
describe("extractErrorMessage", () => {
|
|
15
|
+
describe("Array content handling", () => {
|
|
16
|
+
it("should extract text from array content with multiple text items", () => {
|
|
17
|
+
const content = [
|
|
18
|
+
{ type: "text", text: "Error:" },
|
|
19
|
+
{ type: "text", text: "Tool execution failed" },
|
|
20
|
+
{ type: "image", url: "http://example.com/error.png" }, // Should be filtered out
|
|
21
|
+
];
|
|
22
|
+
const result = extractErrorMessage(content);
|
|
23
|
+
expect(result).toBe("Error: Tool execution failed");
|
|
24
|
+
});
|
|
25
|
+
it("should extract text from array content with single text item", () => {
|
|
26
|
+
const content = [{ type: "text", text: "Simple error message" }];
|
|
27
|
+
const result = extractErrorMessage(content);
|
|
28
|
+
expect(result).toBe("Simple error message");
|
|
29
|
+
});
|
|
30
|
+
it("should return fallback message for array content with no text items", () => {
|
|
31
|
+
const content = [
|
|
32
|
+
{ type: "image", url: "http://example.com/error.png" },
|
|
33
|
+
{ type: "resource", uri: "file://error.log" },
|
|
34
|
+
];
|
|
35
|
+
const result = extractErrorMessage(content);
|
|
36
|
+
expect(result).toBe("Error occurred but no details provided");
|
|
37
|
+
});
|
|
38
|
+
it("should return fallback message for empty array content", () => {
|
|
39
|
+
const content = [];
|
|
40
|
+
const result = extractErrorMessage(content);
|
|
41
|
+
expect(result).toBe("Error occurred but no details provided");
|
|
42
|
+
});
|
|
43
|
+
it("should handle array content with mixed types correctly", () => {
|
|
44
|
+
const content = [
|
|
45
|
+
{ type: "resource", uri: "file://log.txt" },
|
|
46
|
+
{ type: "text", text: "First error" },
|
|
47
|
+
{ type: "image", url: "http://example.com/img.png" },
|
|
48
|
+
{ type: "text", text: "Second error" },
|
|
49
|
+
{ type: "unknown", data: "something" },
|
|
50
|
+
];
|
|
51
|
+
const result = extractErrorMessage(content);
|
|
52
|
+
expect(result).toBe("First error Second error");
|
|
53
|
+
});
|
|
54
|
+
it("should handle array content with malformed items", () => {
|
|
55
|
+
const content = [
|
|
56
|
+
null,
|
|
57
|
+
{ type: "text", text: "Valid error" },
|
|
58
|
+
{ type: "text" }, // Missing text property
|
|
59
|
+
{ type: "text", text: null }, // Invalid text type
|
|
60
|
+
{ type: "text", text: "Another valid error" },
|
|
61
|
+
];
|
|
62
|
+
const result = extractErrorMessage(content);
|
|
63
|
+
expect(result).toBe("Valid error Another valid error");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe("Non-array content handling", () => {
|
|
67
|
+
it("should return string content as-is", () => {
|
|
68
|
+
const content = "Direct error message";
|
|
69
|
+
const result = extractErrorMessage(content);
|
|
70
|
+
expect(result).toBe("Direct error message");
|
|
71
|
+
});
|
|
72
|
+
it("should handle null content", () => {
|
|
73
|
+
const content = null;
|
|
74
|
+
const result = extractErrorMessage(content);
|
|
75
|
+
expect(result).toBe("Unknown error occurred");
|
|
76
|
+
});
|
|
77
|
+
it("should handle undefined content", () => {
|
|
78
|
+
const content = undefined;
|
|
79
|
+
const result = extractErrorMessage(content);
|
|
80
|
+
expect(result).toBe("Unknown error occurred");
|
|
81
|
+
});
|
|
82
|
+
it("should handle number content", () => {
|
|
83
|
+
const content = 42;
|
|
84
|
+
const result = extractErrorMessage(content);
|
|
85
|
+
expect(result).toBe("42");
|
|
86
|
+
});
|
|
87
|
+
it("should handle boolean content", () => {
|
|
88
|
+
const content = false;
|
|
89
|
+
const result = extractErrorMessage(content);
|
|
90
|
+
expect(result).toBe("false");
|
|
91
|
+
});
|
|
92
|
+
it("should handle object content", () => {
|
|
93
|
+
const content = { error: "Something went wrong" };
|
|
94
|
+
const result = extractErrorMessage(content);
|
|
95
|
+
expect(result).toBe('{"error":"Something went wrong"}');
|
|
96
|
+
});
|
|
97
|
+
it("should handle complex object content", () => {
|
|
98
|
+
const content = {
|
|
99
|
+
error: "Something went wrong",
|
|
100
|
+
code: 500,
|
|
101
|
+
details: { message: "Internal server error" },
|
|
102
|
+
};
|
|
103
|
+
const result = extractErrorMessage(content);
|
|
104
|
+
expect(result).toBe('{"error":"Something went wrong","code":500,"details":{"message":"Internal server error"}}');
|
|
105
|
+
});
|
|
106
|
+
it("should handle empty object content", () => {
|
|
107
|
+
const content = {};
|
|
108
|
+
const result = extractErrorMessage(content);
|
|
109
|
+
expect(result).toBe("{}");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=tambo-mcp-provider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/tambo-mcp-provider.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,gDAAgD;AAChD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE;IACpB,YAAY,EAAE;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;KACb;CACF,CAAC,CAAC,CAAC;AAEJ,wDAAwD;AACxD,IAAI,CAAC,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,gBAAgB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC5B,C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AAC,CAAC;QAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC;YAElD,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,OAAO,GAAG;gBACd,KAAK,EAAE,sBAAsB;gBAC7B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;aAC9C,CAAC;YAEF,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CACjB,2FAA2F,CAC5F,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,OAAO,GAAG,EAAE,CAAC;YAEnB,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { extractErrorMessage } from \"../tambo-mcp-provider\";\n\n// Mock the MCP client to avoid ES module issues\njest.mock(\"../mcp-client\", () => ({\n MCPClient: jest.fn(),\n MCPTransport: {\n SSE: \"sse\",\n HTTP: \"http\",\n },\n}));\n\n// Mock the registry provider to avoid dependency issues\njest.mock(\"../../providers/tambo-registry-provider\", () => ({\n useTamboRegistry: jest.fn(),\n}));\n\ndescribe(\"extractErrorMessage\", () => {\n describe(\"Array content handling\", () => {\n it(\"should extract text from array content with multiple text items\", () => {\n const content = [\n { type: \"text\", text: \"Error:\" },\n { type: \"text\", text: \"Tool execution failed\" },\n { type: \"image\", url: \"http://example.com/error.png\" }, // Should be filtered out\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error: Tool execution failed\");\n });\n\n it(\"should extract text from array content with single text item\", () => {\n const content = [{ type: \"text\", text: \"Simple error message\" }];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Simple error message\");\n });\n\n it(\"should return fallback message for array content with no text items\", () => {\n const content = [\n { type: \"image\", url: \"http://example.com/error.png\" },\n { type: \"resource\", uri: \"file://error.log\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should return fallback message for empty array content\", () => {\n const content: any[] = [];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should handle array content with mixed types correctly\", () => {\n const content = [\n { type: \"resource\", uri: \"file://log.txt\" },\n { type: \"text\", text: \"First error\" },\n { type: \"image\", url: \"http://example.com/img.png\" },\n { type: \"text\", text: \"Second error\" },\n { type: \"unknown\", data: \"something\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"First error Second error\");\n });\n\n it(\"should handle array content with malformed items\", () => {\n const content = [\n null,\n { type: \"text\", text: \"Valid error\" },\n { type: \"text\" }, // Missing text property\n { type: \"text\", text: null }, // Invalid text type\n { type: \"text\", text: \"Another valid error\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Valid error Another valid error\");\n });\n });\n\n describe(\"Non-array content handling\", () => {\n it(\"should return string content as-is\", () => {\n const content = \"Direct error message\";\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Direct error message\");\n });\n\n it(\"should handle null content\", () => {\n const content = null;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle undefined content\", () => {\n const content = undefined;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle number content\", () => {\n const content = 42;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"42\");\n });\n\n it(\"should handle boolean content\", () => {\n const content = false;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"false\");\n });\n\n it(\"should handle object content\", () => {\n const content = { error: \"Something went wrong\" };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe('{\"error\":\"Something went wrong\"}');\n });\n\n it(\"should handle complex object content\", () => {\n const content = {\n error: \"Something went wrong\",\n code: 500,\n details: { message: \"Internal server error\" },\n };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\n '{\"error\":\"Something went wrong\",\"code\":500,\"details\":{\"message\":\"Internal server error\"}}',\n );\n });\n\n it(\"should handle empty object content\", () => {\n const content = {};\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"{}\");\n });\n });\n});\n"]}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
2
|
import { MCPTransport } from "./mcp-client";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts error message from MCP tool result content.
|
|
5
|
+
* Handles both array and string content formats.
|
|
6
|
+
* Always returns a string, even for invalid/null inputs.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractErrorMessage(content: unknown): string;
|
|
3
9
|
export interface McpServerInfo {
|
|
4
10
|
name?: string;
|
|
5
11
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAa,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AACD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAkEA,CAAC"}
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAa,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAsB5D;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AACD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAkEA,CAAC"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { useTamboRegistry } from "../providers/tambo-registry-provider";
|
|
3
3
|
import { MCPClient, MCPTransport } from "./mcp-client";
|
|
4
|
+
/**
|
|
5
|
+
* Extracts error message from MCP tool result content.
|
|
6
|
+
* Handles both array and string content formats.
|
|
7
|
+
* Always returns a string, even for invalid/null inputs.
|
|
8
|
+
*/
|
|
9
|
+
export function extractErrorMessage(content) {
|
|
10
|
+
if (content === undefined || content === null) {
|
|
11
|
+
return "Unknown error occurred";
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(content)) {
|
|
14
|
+
const textItems = content
|
|
15
|
+
.filter((item) => item && item.type === "text" && typeof item.text === "string")
|
|
16
|
+
.map((item) => item.text);
|
|
17
|
+
return textItems.length > 0
|
|
18
|
+
? textItems.join(" ")
|
|
19
|
+
: "Error occurred but no details provided";
|
|
20
|
+
}
|
|
21
|
+
if (typeof content === "object") {
|
|
22
|
+
return JSON.stringify(content);
|
|
23
|
+
}
|
|
24
|
+
return `${content}`;
|
|
25
|
+
}
|
|
4
26
|
/**
|
|
5
27
|
* This provider is used to register tools from MCP servers.
|
|
6
28
|
* @returns the wrapped children
|
|
@@ -49,8 +71,8 @@ export const TamboMcpProvider = ({ mcpServers, children }) => {
|
|
|
49
71
|
}
|
|
50
72
|
const result = await mcpServer.callTool(tool.name, args);
|
|
51
73
|
if (result.isError) {
|
|
52
|
-
|
|
53
|
-
throw new Error(
|
|
74
|
+
const errorMessage = extractErrorMessage(result.content);
|
|
75
|
+
throw new Error(errorMessage);
|
|
54
76
|
}
|
|
55
77
|
return result.content;
|
|
56
78
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,g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D,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC7B,IAAI,EAAE,CAAC;YACV,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxB,YAAY,CAAC;oBACX,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;oBACnC,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,IAAI,EAAE,KAAK,EAAE,IAA6B,EAAE,EAAE;wBAC5C,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,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","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"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { act, renderHook } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { currentPageContextHelper, currentTimeContextHelper, } from "../../context-helpers";
|
|
4
|
-
import { setHelpers } from "../../context-helpers/registry";
|
|
5
4
|
import { TamboContextHelpersProvider, useTamboContextHelpers, } from "../tambo-context-helpers-provider";
|
|
6
5
|
/**
|
|
7
6
|
* Test suite for TamboContextHelpersProvider (simplified API, registry-backed)
|
|
@@ -18,43 +17,11 @@ import { TamboContextHelpersProvider, useTamboContextHelpers, } from "../tambo-c
|
|
|
18
17
|
describe("TamboContextHelpersProvider", () => {
|
|
19
18
|
// Ensure registry is clean for each test to avoid cross-test contamination
|
|
20
19
|
beforeEach(() => {
|
|
21
|
-
setHelpers({});
|
|
22
20
|
jest.clearAllMocks();
|
|
23
21
|
});
|
|
24
22
|
// Base wrapper with no helpers provided
|
|
25
23
|
const wrapper = ({ children }) => (React.createElement(TamboContextHelpersProvider, null, children));
|
|
26
24
|
describe("useTamboContextHelpers", () => {
|
|
27
|
-
/**
|
|
28
|
-
* NOTE: The hook is registry-backed and safe outside provider. It should not throw.
|
|
29
|
-
* This replaces the previous behavior that threw without a provider.
|
|
30
|
-
*/
|
|
31
|
-
it("should be safe outside provider (registry-backed no provider)", async () => {
|
|
32
|
-
const consoleSpy = jest
|
|
33
|
-
.spyOn(console, "error")
|
|
34
|
-
.mockImplementation(() => { });
|
|
35
|
-
const { result } = renderHook(() => useTamboContextHelpers());
|
|
36
|
-
// Should return callable functions
|
|
37
|
-
expect(typeof result.current.getAdditionalContext).toBe("function");
|
|
38
|
-
expect(typeof result.current.getContextHelpers).toBe("function");
|
|
39
|
-
expect(typeof result.current.addContextHelper).toBe("function");
|
|
40
|
-
expect(typeof result.current.removeContextHelper).toBe("function");
|
|
41
|
-
// Starts empty
|
|
42
|
-
expect(await result.current.getAdditionalContext()).toHaveLength(0);
|
|
43
|
-
// Add a helper and verify
|
|
44
|
-
act(() => {
|
|
45
|
-
result.current.addContextHelper("outsideHelper", () => ({ ok: true }));
|
|
46
|
-
});
|
|
47
|
-
const contexts = await result.current.getAdditionalContext();
|
|
48
|
-
expect(contexts).toContainEqual({
|
|
49
|
-
name: "outsideHelper",
|
|
50
|
-
context: { ok: true },
|
|
51
|
-
});
|
|
52
|
-
// Cleanup
|
|
53
|
-
act(() => {
|
|
54
|
-
result.current.removeContextHelper("outsideHelper");
|
|
55
|
-
});
|
|
56
|
-
consoleSpy.mockRestore();
|
|
57
|
-
});
|
|
58
25
|
/**
|
|
59
26
|
* Verifies that the hook returns the expected API functions when used within a provider.
|
|
60
27
|
*/
|
|
@@ -129,7 +96,6 @@ describe("TamboContextHelpersProvider", () => {
|
|
|
129
96
|
*/
|
|
130
97
|
describe("Custom Context Helpers via contextHelpers config", () => {
|
|
131
98
|
beforeEach(() => {
|
|
132
|
-
setHelpers({});
|
|
133
99
|
jest.clearAllMocks();
|
|
134
100
|
});
|
|
135
101
|
/**
|
|
@@ -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,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AE,KAAK,IAAI,EAAE;QAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;YAC5D,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CACzB,oBAAC,2BAA2B,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,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 { 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,6BAA6B,EAAE,GAAG,EAAE;IAC3C,2EAA2E;IAC3E,UAAU,CAAC,GAAG,EAAE;QACd,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;;WAEG;QACH,EA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EH,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"]}
|
package/esm/providers/__tests__/tambo-interactables-additional-context-edge-cases.test.d.ts.map
ADDED
|
@@ -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":""}
|