@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
|
@@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
const react_1 = require("@testing-library/react");
|
|
20
20
|
const react_2 = __importDefault(require("react"));
|
|
21
|
-
const registry_1 = require("../../context-helpers/registry");
|
|
22
21
|
const tambo_context_helpers_provider_1 = require("../../providers/tambo-context-helpers-provider");
|
|
23
22
|
const index_1 = require("../index");
|
|
24
23
|
/**
|
|
@@ -35,7 +34,6 @@ function wrapper(helpers) {
|
|
|
35
34
|
describe("Context Helpers API", () => {
|
|
36
35
|
// Ensure the global registry doesn't leak state between tests
|
|
37
36
|
beforeEach(() => {
|
|
38
|
-
(0, registry_1.setHelpers)({});
|
|
39
37
|
jest.clearAllMocks();
|
|
40
38
|
});
|
|
41
39
|
test("returns empty array when no helpers provided", async () => {
|
|
@@ -104,7 +102,9 @@ describe("Context Helpers API", () => {
|
|
|
104
102
|
// Initially empty
|
|
105
103
|
expect(await result.current.getAdditionalContext()).toHaveLength(0);
|
|
106
104
|
// Add
|
|
107
|
-
|
|
105
|
+
(0, react_1.act)(() => {
|
|
106
|
+
result.current.addContextHelper("dyn", () => ({ x: 10 }));
|
|
107
|
+
});
|
|
108
108
|
let contexts = await result.current.getAdditionalContext();
|
|
109
109
|
expect(contexts).toHaveLength(1);
|
|
110
110
|
expect(contexts[0]).toEqual({
|
|
@@ -112,7 +112,9 @@ describe("Context Helpers API", () => {
|
|
|
112
112
|
context: { x: 10 },
|
|
113
113
|
});
|
|
114
114
|
// Update
|
|
115
|
-
|
|
115
|
+
(0, react_1.act)(() => {
|
|
116
|
+
result.current.addContextHelper("dyn", () => ({ x: 20 }));
|
|
117
|
+
});
|
|
116
118
|
contexts = await result.current.getAdditionalContext();
|
|
117
119
|
expect(contexts).toHaveLength(1);
|
|
118
120
|
expect(contexts[0]).toEqual({
|
|
@@ -120,7 +122,9 @@ describe("Context Helpers API", () => {
|
|
|
120
122
|
context: { x: 20 },
|
|
121
123
|
});
|
|
122
124
|
// Remove
|
|
123
|
-
|
|
125
|
+
(0, react_1.act)(() => {
|
|
126
|
+
result.current.removeContextHelper("dyn");
|
|
127
|
+
});
|
|
124
128
|
contexts = await result.current.getAdditionalContext();
|
|
125
129
|
expect(contexts).toHaveLength(0);
|
|
126
130
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers-provider.test.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;AAEH,kDAAoD;AACpD,kDAAiD;AACjD,6DAA4D;AAC5D,mGAGwD;AACxD,oCAKkB;AAElB;;;;GAIG;AACH,SAAS,OAAO,CAAC,OAAyC;IACxD,8CAA8C;IAC9C,OAAO,CAAC,EAAE,QAAQ,EAAqB,EAAE,EAAE,CACzC,eAAK,CAAC,aAAa,CACjB,4DAA2B,EAC3B;QACE,cAAc,EAAE,OAAO;KACxB,EACD,QAAQ,CACT,CAAC;AACN,CAAC;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,8DAA8D;IAC9D,UAAU,CAAC,GAAG,EAAE;QACd,IAAA,qBAAU,EAAC,EAAE,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,uDAAsB,GAAE,EAAE;YAC5D,OAAO,EAAE,OAAO,EAAE;SACnB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAC7D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CA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E,yCAAyC;QACzC,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAE,CAAC,OAG7D,CAAC;YACF,MAAM,CACJ,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,SAAS,CAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,CACJ,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,CACnE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for the Context Helpers API.\n *\n * The new API treats a context helper as a plain function that returns a value\n * to include in context, or null/undefined to skip. The provider wraps each\n * value with its key name as { name, context } before sending with messages.\n *\n * This test suite validates that:\n * - Helper functions can return sync/async values.\n * - Returning null/undefined causes the helper to be skipped.\n * - Errors in helpers are caught and skipped.\n * - The provider aggregates helpers passed in its props and returns AdditionalContext[].\n */\n\nimport { renderHook } from \"@testing-library/react\";\nimport React, { PropsWithChildren } from \"react\";\nimport { setHelpers } from \"../../context-helpers/registry\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../../providers/tambo-context-helpers-provider\";\nimport {\n type AdditionalContext,\n type ContextHelperFn,\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../index\";\n\n/**\n * Test wrapper to provide the TamboContextHelpersProvider for hooks.\n * @param helpers - A dictionary of context helper functions.\n * @returns A wrapper component that provides the TamboContextHelpersProvider.\n */\nfunction wrapper(helpers?: Record<string, ContextHelperFn>) {\n // eslint-disable-next-line react/display-name\n return ({ children }: PropsWithChildren) =>\n React.createElement(\n TamboContextHelpersProvider,\n {\n contextHelpers: helpers,\n },\n children,\n );\n}\n\ndescribe(\"Context Helpers API\", () => {\n // Ensure the global registry doesn't leak state between tests\n beforeEach(() => {\n setHelpers({});\n jest.clearAllMocks();\n });\n\n test(\"returns empty array when no helpers provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(Array.isArray(contexts)).toBe(true);\n expect(contexts).toHaveLength(0);\n });\n\n test(\"collects sync and async helper results\", async () => {\n const syncHelper: ContextHelperFn = () => ({ a: 1 });\n const asyncHelper: ContextHelperFn = async () => ({ b: 2 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n sync: syncHelper,\n async: asyncHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Validate shape and presence\n const byName = new Map(contexts.map((c) => [c.name, c.context]));\n expect(byName.get(\"sync\")).toEqual({ a: 1 });\n expect(byName.get(\"async\")).toEqual({ b: 2 });\n });\n\n test(\"skips null and undefined results\", async () => {\n const nullHelper: ContextHelperFn = () => null;\n const undefinedHelper: ContextHelperFn = () => undefined;\n const validHelper: ContextHelperFn = () => ({ ok: true });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n nullHelper,\n undefinedHelper,\n validHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n expect(names).toContain(\"validHelper\");\n expect(names).not.toContain(\"nullHelper\");\n expect(names).not.toContain(\"undefinedHelper\");\n });\n\n test(\"errors in helpers are caught and skipped\", async () => {\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation(() => {\n // silence expected error\n });\n\n const badHelper: ContextHelperFn = () => {\n throw new Error(\"boom\");\n };\n const goodHelper: ContextHelperFn = () => ({ ok: 1 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({ badHelper, goodHelper }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"goodHelper\",\n context: { ok: 1 },\n });\n\n consoleSpy.mockRestore();\n });\n\n test(\"dynamic add/remove helpers works\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n // Initially empty\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n // Add\n result.current.addContextHelper(\"dyn\", () => ({ x: 10 }));\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 10 },\n });\n\n // Update\n result.current.addContextHelper(\"dyn\", () => ({ x: 20 }));\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 20 },\n });\n\n // Remove\n result.current.removeContextHelper(\"dyn\");\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n test(\"prebuilt helpers can be passed directly\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Should include both entries unless environment prevents userPage (SSR)\n const names = contexts.map((c) => c.name);\n expect(names).toContain(\"userTime\");\n // userPage may be null on non-browser envs; allow either outcome:\n // if present, ensure expected keys exist\n if (names.includes(\"userPage\")) {\n const userPage = contexts.find((c) => c.name === \"userPage\")!.context as {\n url?: string;\n title?: string;\n };\n expect(\n typeof userPage.url === \"string\" || userPage.url === undefined,\n ).toBe(true);\n expect(\n typeof userPage.title === \"string\" || userPage.title === undefined,\n ).toBe(true);\n }\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"context-helpers-provider.test.js","sourceRoot":"","sources":["../../../src/context-helpers/__tests__/context-helpers-provider.test.tsx"],"names":[],"mappings":";AAAA;;;;;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,QAAQ,CAAC,GAAG,KAAK,SAAS,CAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,CACJ,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,CACnE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for the Context Helpers API.\n *\n * The new API treats a context helper as a plain function that returns a value\n * to include in context, or null/undefined to skip. The provider wraps each\n * value with its key name as { name, context } before sending with messages.\n *\n * This test suite validates that:\n * - Helper functions can return sync/async values.\n * - Returning null/undefined causes the helper to be skipped.\n * - Errors in helpers are caught and skipped.\n * - The provider aggregates helpers passed in its props and returns AdditionalContext[].\n */\n\nimport { act, renderHook } from \"@testing-library/react\";\nimport React, { PropsWithChildren } from \"react\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../../providers/tambo-context-helpers-provider\";\nimport {\n type AdditionalContext,\n type ContextHelperFn,\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../index\";\n\n/**\n * Test wrapper to provide the TamboContextHelpersProvider for hooks.\n * @param helpers - A dictionary of context helper functions.\n * @returns A wrapper component that provides the TamboContextHelpersProvider.\n */\nfunction wrapper(helpers?: Record<string, ContextHelperFn>) {\n // eslint-disable-next-line react/display-name\n return ({ children }: PropsWithChildren) =>\n React.createElement(\n TamboContextHelpersProvider,\n {\n contextHelpers: helpers,\n },\n children,\n );\n}\n\ndescribe(\"Context Helpers API\", () => {\n // Ensure the global registry doesn't leak state between tests\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n test(\"returns empty array when no helpers provided\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(Array.isArray(contexts)).toBe(true);\n expect(contexts).toHaveLength(0);\n });\n\n test(\"collects sync and async helper results\", async () => {\n const syncHelper: ContextHelperFn = () => ({ a: 1 });\n const asyncHelper: ContextHelperFn = async () => ({ b: 2 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n sync: syncHelper,\n async: asyncHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Validate shape and presence\n const byName = new Map(contexts.map((c) => [c.name, c.context]));\n expect(byName.get(\"sync\")).toEqual({ a: 1 });\n expect(byName.get(\"async\")).toEqual({ b: 2 });\n });\n\n test(\"skips null and undefined results\", async () => {\n const nullHelper: ContextHelperFn = () => null;\n const undefinedHelper: ContextHelperFn = () => undefined;\n const validHelper: ContextHelperFn = () => ({ ok: true });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n nullHelper,\n undefinedHelper,\n validHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n const names = contexts.map((c) => c.name);\n\n expect(names).toContain(\"validHelper\");\n expect(names).not.toContain(\"nullHelper\");\n expect(names).not.toContain(\"undefinedHelper\");\n });\n\n test(\"errors in helpers are caught and skipped\", async () => {\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation(() => {\n // silence expected error\n });\n\n const badHelper: ContextHelperFn = () => {\n throw new Error(\"boom\");\n };\n const goodHelper: ContextHelperFn = () => ({ ok: 1 });\n\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({ badHelper, goodHelper }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"goodHelper\",\n context: { ok: 1 },\n });\n\n consoleSpy.mockRestore();\n });\n\n test(\"dynamic add/remove helpers works\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper(),\n });\n\n // Initially empty\n expect(await result.current.getAdditionalContext()).toHaveLength(0);\n\n // Add\n act(() => {\n result.current.addContextHelper(\"dyn\", () => ({ x: 10 }));\n });\n\n let contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 10 },\n });\n\n // Update\n act(() => {\n result.current.addContextHelper(\"dyn\", () => ({ x: 20 }));\n });\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(1);\n expect(contexts[0]).toEqual<AdditionalContext>({\n name: \"dyn\",\n context: { x: 20 },\n });\n\n // Remove\n act(() => {\n result.current.removeContextHelper(\"dyn\");\n });\n contexts = await result.current.getAdditionalContext();\n expect(contexts).toHaveLength(0);\n });\n\n test(\"prebuilt helpers can be passed directly\", async () => {\n const { result } = renderHook(() => useTamboContextHelpers(), {\n wrapper: wrapper({\n userTime: currentTimeContextHelper,\n userPage: currentPageContextHelper,\n }),\n });\n\n const contexts = await result.current.getAdditionalContext();\n\n // Should include both entries unless environment prevents userPage (SSR)\n const names = contexts.map((c) => c.name);\n expect(names).toContain(\"userTime\");\n // userPage may be null on non-browser envs; allow either outcome:\n // if present, ensure expected keys exist\n if (names.includes(\"userPage\")) {\n const userPage = contexts.find((c) => c.name === \"userPage\")!.context as {\n url?: string;\n title?: string;\n };\n expect(\n typeof userPage.url === \"string\" || userPage.url === undefined,\n ).toBe(true);\n expect(\n typeof userPage.title === \"string\" || userPage.title === undefined,\n ).toBe(true);\n }\n });\n});\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ContextHelperFn } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Prebuilt context helper that provides information about all interactable components currently on the page.
|
|
4
|
+
* This gives the AI awareness of what components it can interact with and their current state.
|
|
5
|
+
* @returns an object with description and components, or null to skip including this context.
|
|
6
|
+
* To disable this helper, override it with a function that returns null:
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // To disable the default interactables context
|
|
10
|
+
* const { addContextHelper } = useTamboContextHelpers();
|
|
11
|
+
* addContextHelper("interactables", () => null);
|
|
12
|
+
*
|
|
13
|
+
* // To customize the context
|
|
14
|
+
* addContextHelper("interactables", () => ({
|
|
15
|
+
* description: "Custom description",
|
|
16
|
+
* components: getCustomComponentsSubset()
|
|
17
|
+
* }));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const currentInteractablesContextHelper: ContextHelperFn;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an interactables context helper with access to the current components.
|
|
23
|
+
* This is used internally by TamboInteractableProvider.
|
|
24
|
+
* @param getComponents Function to get current interactable components
|
|
25
|
+
* @returns Context helper function
|
|
26
|
+
*/
|
|
27
|
+
export declare const createInteractablesContextHelper: (getComponents: () => any[]) => ContextHelperFn;
|
|
28
|
+
//# sourceMappingURL=current-interactables-context-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-interactables-context-helper.d.ts","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iCAAiC,EAAE,eAI/C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAC3C,eAAe,MAAM,GAAG,EAAE,KACzB,eA2BF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInteractablesContextHelper = exports.currentInteractablesContextHelper = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Prebuilt context helper that provides information about all interactable components currently on the page.
|
|
6
|
+
* This gives the AI awareness of what components it can interact with and their current state.
|
|
7
|
+
* @returns an object with description and components, or null to skip including this context.
|
|
8
|
+
* To disable this helper, override it with a function that returns null:
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* // To disable the default interactables context
|
|
12
|
+
* const { addContextHelper } = useTamboContextHelpers();
|
|
13
|
+
* addContextHelper("interactables", () => null);
|
|
14
|
+
*
|
|
15
|
+
* // To customize the context
|
|
16
|
+
* addContextHelper("interactables", () => ({
|
|
17
|
+
* description: "Custom description",
|
|
18
|
+
* components: getCustomComponentsSubset()
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const currentInteractablesContextHelper = () => {
|
|
23
|
+
// This will be provided by the interactable provider when it registers this helper
|
|
24
|
+
// Since we're provider-only now, this function gets replaced at runtime
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
exports.currentInteractablesContextHelper = currentInteractablesContextHelper;
|
|
28
|
+
/**
|
|
29
|
+
* Creates an interactables context helper with access to the current components.
|
|
30
|
+
* This is used internally by TamboInteractableProvider.
|
|
31
|
+
* @param getComponents Function to get current interactable components
|
|
32
|
+
* @returns Context helper function
|
|
33
|
+
*/
|
|
34
|
+
const createInteractablesContextHelper = (getComponents) => {
|
|
35
|
+
return () => {
|
|
36
|
+
try {
|
|
37
|
+
const components = getComponents();
|
|
38
|
+
if (!Array.isArray(components) || components.length === 0) {
|
|
39
|
+
return null; // No interactable components on the page
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
description: "These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, and optional schema. You can use tools to update these components on behalf of the user.",
|
|
43
|
+
components: components.map((component) => ({
|
|
44
|
+
id: component.id,
|
|
45
|
+
componentName: component.name,
|
|
46
|
+
description: component.description,
|
|
47
|
+
props: component.props,
|
|
48
|
+
propsSchema: component.propsSchema
|
|
49
|
+
? "Available - use component-specific update tools"
|
|
50
|
+
: "Not specified",
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error("currentInteractablesContextHelper failed:", e);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.createInteractablesContextHelper = createInteractablesContextHelper;
|
|
61
|
+
//# sourceMappingURL=current-interactables-context-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-interactables-context-helper.js","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,iCAAiC,GAAoB,GAAG,EAAE;IACrE,mFAAmF;IACnF,wEAAwE;IACxE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAJW,QAAA,iCAAiC,qCAI5C;AAEF;;;;;GAKG;AACI,MAAM,gCAAgC,GAAG,CAC9C,aAA0B,EACT,EAAE;IACnB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;YAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1D,OAAO,IAAI,CAAC,CAAC,yCAAyC;YACxD,CAAC;YAED,OAAO;gBACL,WAAW,EACT,oPAAoP;gBACtP,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;oBACzC,EAAE,EAAE,SAAS,CAAC,EAAE;oBAChB,aAAa,EAAE,SAAS,CAAC,IAAI;oBAC7B,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,WAAW,EAAE,SAAS,CAAC,WAAW;wBAChC,CAAC,CAAC,iDAAiD;wBACnD,CAAC,CAAC,eAAe;iBACpB,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,CAAC,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,gCAAgC,oCA6B3C","sourcesContent":["import { ContextHelperFn } from \"./types\";\n\n/**\n * Prebuilt context helper that provides information about all interactable components currently on the page.\n * This gives the AI awareness of what components it can interact with and their current state.\n * @returns an object with description and components, or null to skip including this context.\n * To disable this helper, override it with a function that returns null:\n * @example\n * ```tsx\n * // To disable the default interactables context\n * const { addContextHelper } = useTamboContextHelpers();\n * addContextHelper(\"interactables\", () => null);\n *\n * // To customize the context\n * addContextHelper(\"interactables\", () => ({\n * description: \"Custom description\",\n * components: getCustomComponentsSubset()\n * }));\n * ```\n */\nexport const currentInteractablesContextHelper: ContextHelperFn = () => {\n // This will be provided by the interactable provider when it registers this helper\n // Since we're provider-only now, this function gets replaced at runtime\n return null;\n};\n\n/**\n * Creates an interactables context helper with access to the current components.\n * This is used internally by TamboInteractableProvider.\n * @param getComponents Function to get current interactable components\n * @returns Context helper function\n */\nexport const createInteractablesContextHelper = (\n getComponents: () => any[],\n): ContextHelperFn => {\n return () => {\n try {\n const components = getComponents();\n\n if (!Array.isArray(components) || components.length === 0) {\n return null; // No interactable components on the page\n }\n\n return {\n description:\n \"These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, and optional schema. You can use tools to update these components on behalf of the user.\",\n components: components.map((component) => ({\n id: component.id,\n componentName: component.name,\n description: component.description,\n props: component.props,\n propsSchema: component.propsSchema\n ? \"Available - use component-specific update tools\"\n : \"Not specified\",\n })),\n };\n } catch (e) {\n console.error(\"currentInteractablesContextHelper failed:\", e);\n return null;\n }\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,SAAS,CAAC"}
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./current-page-context-helper"), exports);
|
|
18
18
|
__exportStar(require("./current-time-context-helper"), exports);
|
|
19
|
+
__exportStar(require("./current-interactables-context-helper"), exports);
|
|
19
20
|
__exportStar(require("./types"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,gEAA8C;AAC9C,0CAAwB","sourcesContent":["export * from \"./current-page-context-helper\";\nexport * from \"./current-time-context-helper\";\nexport * from \"./types\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,gEAA8C;AAC9C,yEAAuD;AACvD,0CAAwB","sourcesContent":["export * from \"./current-page-context-helper\";\nexport * from \"./current-time-context-helper\";\nexport * from \"./current-interactables-context-helper\";\nexport * from \"./types\";\n"]}
|
|
@@ -3,32 +3,11 @@
|
|
|
3
3
|
* Consumers can add/remove helpers and resolve additional context anywhere.
|
|
4
4
|
*/
|
|
5
5
|
export type HelperFn = () => any | null | undefined | Promise<any | null | undefined>;
|
|
6
|
-
/**
|
|
7
|
-
* Get the current helpers map (by reference).
|
|
8
|
-
* @returns The current helpers map.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getHelpers(): Record<string, HelperFn>;
|
|
11
|
-
/**
|
|
12
|
-
* Replace the entire helpers map (used for hydration/reset in tests).
|
|
13
|
-
* @param next - The new helpers map.
|
|
14
|
-
*/
|
|
15
|
-
export declare function setHelpers(next: Record<string, HelperFn>): void;
|
|
16
|
-
/**
|
|
17
|
-
* Add or replace a helper.
|
|
18
|
-
* @param name - The name of the helper.
|
|
19
|
-
* @param fn - The helper function.
|
|
20
|
-
*/
|
|
21
|
-
export declare function addHelper(name: string, fn: HelperFn): void;
|
|
22
|
-
/**
|
|
23
|
-
* Remove a helper by name.
|
|
24
|
-
* @param name - The name of the helper.
|
|
25
|
-
*/
|
|
26
|
-
export declare function removeHelper(name: string): void;
|
|
27
6
|
/**
|
|
28
7
|
* Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
|
|
29
8
|
* @returns The resolved additional context.
|
|
30
9
|
*/
|
|
31
|
-
export declare function resolveAdditionalContext(): Promise<{
|
|
10
|
+
export declare function resolveAdditionalContext(helpers: Record<string, HelperFn>): Promise<{
|
|
32
11
|
name: string;
|
|
33
12
|
context: any;
|
|
34
13
|
}[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,MACnB,GAAG,GACH,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,MACnB,GAAG,GACH,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEpC;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAChC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,EAAE,CAAC,CAkB3C"}
|
|
@@ -4,46 +4,12 @@
|
|
|
4
4
|
* Consumers can add/remove helpers and resolve additional context anywhere.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getHelpers = getHelpers;
|
|
8
|
-
exports.setHelpers = setHelpers;
|
|
9
|
-
exports.addHelper = addHelper;
|
|
10
|
-
exports.removeHelper = removeHelper;
|
|
11
7
|
exports.resolveAdditionalContext = resolveAdditionalContext;
|
|
12
|
-
let helpers = {};
|
|
13
|
-
/**
|
|
14
|
-
* Get the current helpers map (by reference).
|
|
15
|
-
* @returns The current helpers map.
|
|
16
|
-
*/
|
|
17
|
-
function getHelpers() {
|
|
18
|
-
return helpers;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Replace the entire helpers map (used for hydration/reset in tests).
|
|
22
|
-
* @param next - The new helpers map.
|
|
23
|
-
*/
|
|
24
|
-
function setHelpers(next) {
|
|
25
|
-
helpers = next;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Add or replace a helper.
|
|
29
|
-
* @param name - The name of the helper.
|
|
30
|
-
* @param fn - The helper function.
|
|
31
|
-
*/
|
|
32
|
-
function addHelper(name, fn) {
|
|
33
|
-
helpers[name] = fn;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Remove a helper by name.
|
|
37
|
-
* @param name - The name of the helper.
|
|
38
|
-
*/
|
|
39
|
-
function removeHelper(name) {
|
|
40
|
-
delete helpers[name];
|
|
41
|
-
}
|
|
42
8
|
/**
|
|
43
9
|
* Resolve all helpers to AdditionalContext entries, skipping null/undefined and errors.
|
|
44
10
|
* @returns The resolved additional context.
|
|
45
11
|
*/
|
|
46
|
-
async function resolveAdditionalContext() {
|
|
12
|
+
async function resolveAdditionalContext(helpers) {
|
|
47
13
|
const entries = Object.entries(helpers);
|
|
48
14
|
if (entries.length === 0)
|
|
49
15
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/context-helpers/registry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAYH,4DAoBC;AAxBD;;;GAGG;AACI,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/dist/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/dist/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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AAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.currentTimeContextHelper = exports.currentPageContextHelper = exports.useTamboInteractable = exports.withInteractable = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThreadInput = exports.useTamboThread = exports.useTamboStream = exports.useTamboGenerationStage = exports.useTamboContextHelpers = exports.useTamboClient = exports.useTambo = exports.useIsTamboTokenUpdating = exports.TamboThreadProvider = exports.TamboThreadInputProvider = exports.TamboStubProvider = exports.TamboProvider = exports.TamboPropStreamProvider = exports.TamboContextHelpersProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
|
|
18
|
+
exports.currentTimeContextHelper = exports.currentPageContextHelper = exports.useCurrentInteractablesSnapshot = exports.useTamboInteractable = exports.withInteractable = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThreadInput = exports.useTamboThread = exports.useTamboStream = exports.useTamboGenerationStage = exports.useTamboContextHelpers = exports.useTamboClient = exports.useTambo = exports.useIsTamboTokenUpdating = exports.TamboThreadProvider = exports.TamboThreadInputProvider = exports.TamboStubProvider = exports.TamboProvider = exports.TamboPropStreamProvider = exports.TamboContextHelpersProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboStreamStatus = exports.useTamboStreamingProps = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
|
|
19
19
|
var use_component_state_1 = require("./hooks/use-component-state");
|
|
20
20
|
Object.defineProperty(exports, "useTamboComponentState", { enumerable: true, get: function () { return use_component_state_1.useTamboComponentState; } });
|
|
21
21
|
var use_current_message_1 = require("./hooks/use-current-message");
|
|
@@ -52,6 +52,7 @@ var with_tambo_interactable_1 = require("./providers/hoc/with-tambo-interactable
|
|
|
52
52
|
Object.defineProperty(exports, "withInteractable", { enumerable: true, get: function () { return with_tambo_interactable_1.withTamboInteractable; } });
|
|
53
53
|
var tambo_interactable_provider_1 = require("./providers/tambo-interactable-provider");
|
|
54
54
|
Object.defineProperty(exports, "useTamboInteractable", { enumerable: true, get: function () { return tambo_interactable_provider_1.useTamboInteractable; } });
|
|
55
|
+
Object.defineProperty(exports, "useCurrentInteractablesSnapshot", { enumerable: true, get: function () { return tambo_interactable_provider_1.useCurrentInteractablesSnapshot; } });
|
|
55
56
|
// Context helpers exports
|
|
56
57
|
var context_helpers_1 = require("./context-helpers");
|
|
57
58
|
Object.defineProperty(exports, "currentPageContextHelper", { enumerable: true, get: function () { return context_helpers_1.currentPageContextHelper; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wKAAwK;;;;;;;;;;;;;;;;;AAExK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAGqC;AAFnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,2EAIyC;AAHvC,+HAAA,oBAAoB,OAAA;AAKtB,gCAAgC;AAChC,yCAuBqB;AAtBnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,wHAAA,2BAA2B,OAAA;AAC3B,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBA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AAF3C,8HAAA,eAAe,OAAA;AASjB,mFAIiD;AAH/C,2HAAA,qBAAqB,OAAoB;AAI3C,uFAGiD;AAF/C,mIAAA,oBAAoB,OAAA;AACpB,8IAAA,+BAA+B,OAAA;AAGjC,0BAA0B;AAC1B,qDAG2B;AAFzB,2HAAA,wBAAwB,OAAA;AACxB,2HAAA,wBAAwB,OAAA","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,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tambo_mcp_provider_1 = require("../tambo-mcp-provider");
|
|
4
|
+
// Mock the MCP client to avoid ES module issues
|
|
5
|
+
jest.mock("../mcp-client", () => ({
|
|
6
|
+
MCPClient: jest.fn(),
|
|
7
|
+
MCPTransport: {
|
|
8
|
+
SSE: "sse",
|
|
9
|
+
HTTP: "http",
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
// Mock the registry provider to avoid dependency issues
|
|
13
|
+
jest.mock("../../providers/tambo-registry-provider", () => ({
|
|
14
|
+
useTamboRegistry: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
describe("extractErrorMessage", () => {
|
|
17
|
+
describe("Array content handling", () => {
|
|
18
|
+
it("should extract text from array content with multiple text items", () => {
|
|
19
|
+
const content = [
|
|
20
|
+
{ type: "text", text: "Error:" },
|
|
21
|
+
{ type: "text", text: "Tool execution failed" },
|
|
22
|
+
{ type: "image", url: "http://example.com/error.png" }, // Should be filtered out
|
|
23
|
+
];
|
|
24
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
25
|
+
expect(result).toBe("Error: Tool execution failed");
|
|
26
|
+
});
|
|
27
|
+
it("should extract text from array content with single text item", () => {
|
|
28
|
+
const content = [{ type: "text", text: "Simple error message" }];
|
|
29
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
30
|
+
expect(result).toBe("Simple error message");
|
|
31
|
+
});
|
|
32
|
+
it("should return fallback message for array content with no text items", () => {
|
|
33
|
+
const content = [
|
|
34
|
+
{ type: "image", url: "http://example.com/error.png" },
|
|
35
|
+
{ type: "resource", uri: "file://error.log" },
|
|
36
|
+
];
|
|
37
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
38
|
+
expect(result).toBe("Error occurred but no details provided");
|
|
39
|
+
});
|
|
40
|
+
it("should return fallback message for empty array content", () => {
|
|
41
|
+
const content = [];
|
|
42
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
43
|
+
expect(result).toBe("Error occurred but no details provided");
|
|
44
|
+
});
|
|
45
|
+
it("should handle array content with mixed types correctly", () => {
|
|
46
|
+
const content = [
|
|
47
|
+
{ type: "resource", uri: "file://log.txt" },
|
|
48
|
+
{ type: "text", text: "First error" },
|
|
49
|
+
{ type: "image", url: "http://example.com/img.png" },
|
|
50
|
+
{ type: "text", text: "Second error" },
|
|
51
|
+
{ type: "unknown", data: "something" },
|
|
52
|
+
];
|
|
53
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
54
|
+
expect(result).toBe("First error Second error");
|
|
55
|
+
});
|
|
56
|
+
it("should handle array content with malformed items", () => {
|
|
57
|
+
const content = [
|
|
58
|
+
null,
|
|
59
|
+
{ type: "text", text: "Valid error" },
|
|
60
|
+
{ type: "text" }, // Missing text property
|
|
61
|
+
{ type: "text", text: null }, // Invalid text type
|
|
62
|
+
{ type: "text", text: "Another valid error" },
|
|
63
|
+
];
|
|
64
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
65
|
+
expect(result).toBe("Valid error Another valid error");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("Non-array content handling", () => {
|
|
69
|
+
it("should return string content as-is", () => {
|
|
70
|
+
const content = "Direct error message";
|
|
71
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
72
|
+
expect(result).toBe("Direct error message");
|
|
73
|
+
});
|
|
74
|
+
it("should handle null content", () => {
|
|
75
|
+
const content = null;
|
|
76
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
77
|
+
expect(result).toBe("Unknown error occurred");
|
|
78
|
+
});
|
|
79
|
+
it("should handle undefined content", () => {
|
|
80
|
+
const content = undefined;
|
|
81
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
82
|
+
expect(result).toBe("Unknown error occurred");
|
|
83
|
+
});
|
|
84
|
+
it("should handle number content", () => {
|
|
85
|
+
const content = 42;
|
|
86
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
87
|
+
expect(result).toBe("42");
|
|
88
|
+
});
|
|
89
|
+
it("should handle boolean content", () => {
|
|
90
|
+
const content = false;
|
|
91
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
92
|
+
expect(result).toBe("false");
|
|
93
|
+
});
|
|
94
|
+
it("should handle object content", () => {
|
|
95
|
+
const content = { error: "Something went wrong" };
|
|
96
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
97
|
+
expect(result).toBe('{"error":"Something went wrong"}');
|
|
98
|
+
});
|
|
99
|
+
it("should handle complex object content", () => {
|
|
100
|
+
const content = {
|
|
101
|
+
error: "Something went wrong",
|
|
102
|
+
code: 500,
|
|
103
|
+
details: { message: "Internal server error" },
|
|
104
|
+
};
|
|
105
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
106
|
+
expect(result).toBe('{"error":"Something went wrong","code":500,"details":{"message":"Internal server error"}}');
|
|
107
|
+
});
|
|
108
|
+
it("should handle empty object content", () => {
|
|
109
|
+
const content = {};
|
|
110
|
+
const result = (0, tambo_mcp_provider_1.extractErrorMessage)(content);
|
|
111
|
+
expect(result).toBe("{}");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
//# 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,8DAA4D;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,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,OAAO,GAAG;gBACd,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE;gBAC/C,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,8BAA8B,EAAE,EAAE,yBAAyB;aAClF,CAAC;YAEF,MAAM,MAAM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gBACd,KAAK,EAAE,sBAAsB;gBAC7B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;aAC9C,CAAC;YAEF,MAAM,MAAM,GAAG,IAAA,wCAAmB,EAAC,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,IAAA,wCAAmB,EAAC,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,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TamboMcpProvider = void 0;
|
|
4
|
+
exports.extractErrorMessage = extractErrorMessage;
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const tambo_registry_provider_1 = require("../providers/tambo-registry-provider");
|
|
6
7
|
const mcp_client_1 = require("./mcp-client");
|
|
8
|
+
/**
|
|
9
|
+
* Extracts error message from MCP tool result content.
|
|
10
|
+
* Handles both array and string content formats.
|
|
11
|
+
* Always returns a string, even for invalid/null inputs.
|
|
12
|
+
*/
|
|
13
|
+
function extractErrorMessage(content) {
|
|
14
|
+
if (content === undefined || content === null) {
|
|
15
|
+
return "Unknown error occurred";
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(content)) {
|
|
18
|
+
const textItems = content
|
|
19
|
+
.filter((item) => item && item.type === "text" && typeof item.text === "string")
|
|
20
|
+
.map((item) => item.text);
|
|
21
|
+
return textItems.length > 0
|
|
22
|
+
? textItems.join(" ")
|
|
23
|
+
: "Error occurred but no details provided";
|
|
24
|
+
}
|
|
25
|
+
if (typeof content === "object") {
|
|
26
|
+
return JSON.stringify(content);
|
|
27
|
+
}
|
|
28
|
+
return `${content}`;
|
|
29
|
+
}
|
|
7
30
|
/**
|
|
8
31
|
* This provider is used to register tools from MCP servers.
|
|
9
32
|
* @returns the wrapped children
|
|
@@ -52,8 +75,8 @@ const TamboMcpProvider = ({ mcpServers, children }) => {
|
|
|
52
75
|
}
|
|
53
76
|
const result = await mcpServer.callTool(tool.name, args);
|
|
54
77
|
if (result.isError) {
|
|
55
|
-
|
|
56
|
-
throw new Error(
|
|
78
|
+
const errorMessage = extractErrorMessage(result.content);
|
|
79
|
+
throw new Error(errorMessage);
|
|
57
80
|
}
|
|
58
81
|
return result.content;
|
|
59
82
|
},
|