@tambo-ai/react 0.67.0 → 0.67.1
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/LICENSE +21 -0
- package/dist/hooks/use-tambo-threads.d.ts +3 -8
- package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
- package/dist/hooks/use-tambo-threads.js +6 -4
- package/dist/hooks/use-tambo-threads.js.map +1 -1
- package/dist/hooks/use-tambo-threads.test.js +12 -2
- package/dist/hooks/use-tambo-threads.test.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +1 -2
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +4 -4
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js +1 -0
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/dist/providers/tambo-stubs.test.js +1 -1
- package/dist/providers/tambo-stubs.test.js.map +1 -1
- package/dist/providers/tambo-thread-input-provider.d.ts +1 -6
- package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-input-provider.js +4 -5
- package/dist/providers/tambo-thread-input-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts +5 -0
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +5 -2
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/esm/hooks/use-tambo-threads.d.ts +3 -8
- package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
- package/esm/hooks/use-tambo-threads.js +6 -4
- package/esm/hooks/use-tambo-threads.js.map +1 -1
- package/esm/hooks/use-tambo-threads.test.js +12 -2
- package/esm/hooks/use-tambo-threads.test.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +1 -2
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +5 -5
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js +1 -0
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/esm/providers/tambo-stubs.test.js +1 -1
- package/esm/providers/tambo-stubs.test.js.map +1 -1
- package/esm/providers/tambo-thread-input-provider.d.ts +1 -6
- package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-input-provider.js +4 -5
- package/esm/providers/tambo-thread-input-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts +5 -0
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +5 -2
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/package.json +8 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fractal Dynamics Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -6,24 +6,19 @@ interface UseTamboThreadListConfig {
|
|
|
6
6
|
* will be used.
|
|
7
7
|
*/
|
|
8
8
|
projectId?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The context key to get the threads for. If not provided, all threads for
|
|
11
|
-
* the project will be returned.
|
|
12
|
-
*/
|
|
13
|
-
contextKey?: string;
|
|
14
9
|
}
|
|
15
10
|
/**
|
|
16
11
|
* Get all the threads for the specified project.
|
|
17
12
|
*
|
|
18
13
|
* If contextKey is empty, then all threads for the project will be returned.
|
|
19
14
|
* If contextKey is not empty, then only the threads for the specified context
|
|
20
|
-
* key will be returned.
|
|
15
|
+
* key will be returned. The contextKey is obtained from the TamboThreadProvider
|
|
16
|
+
* via useTamboThread().
|
|
21
17
|
* @param config - The config for the useTamboThreadList hook
|
|
22
18
|
* @param config.projectId - The projectId to get the threads for
|
|
23
|
-
* @param config.contextKey - The context key to get the threads for
|
|
24
19
|
* @returns The threads for the specified project and optional context key
|
|
25
20
|
*/
|
|
26
|
-
export declare function useTamboThreadList({ projectId
|
|
21
|
+
export declare function useTamboThreadList({ projectId }?: UseTamboThreadListConfig, options?: Partial<UseQueryOptions<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null>>): import("@tanstack/react-query").QueryObserverRefetchErrorResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverSuccessResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverLoadingErrorResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverPendingResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | import("@tanstack/react-query").QueryObserverPlaceholderResult<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null, Error> | {
|
|
27
22
|
error: Error;
|
|
28
23
|
isError: true;
|
|
29
24
|
isPending: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxD,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,SAAS,EAAE,GAAE,wBAA6B,EAC5C,OAAO,GAAE,OAAO,CACd,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BP"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTamboThreadList = useTamboThreadList;
|
|
4
|
+
const providers_1 = require("../providers");
|
|
4
5
|
const tambo_client_provider_1 = require("../providers/tambo-client-provider");
|
|
5
6
|
const react_query_hooks_1 = require("./react-query-hooks");
|
|
6
7
|
/**
|
|
@@ -8,14 +9,15 @@ const react_query_hooks_1 = require("./react-query-hooks");
|
|
|
8
9
|
*
|
|
9
10
|
* If contextKey is empty, then all threads for the project will be returned.
|
|
10
11
|
* If contextKey is not empty, then only the threads for the specified context
|
|
11
|
-
* key will be returned.
|
|
12
|
+
* key will be returned. The contextKey is obtained from the TamboThreadProvider
|
|
13
|
+
* via useTamboThread().
|
|
12
14
|
* @param config - The config for the useTamboThreadList hook
|
|
13
15
|
* @param config.projectId - The projectId to get the threads for
|
|
14
|
-
* @param config.contextKey - The context key to get the threads for
|
|
15
16
|
* @returns The threads for the specified project and optional context key
|
|
16
17
|
*/
|
|
17
|
-
function useTamboThreadList({ projectId
|
|
18
|
+
function useTamboThreadList({ projectId } = {}, options = {}) {
|
|
18
19
|
const client = (0, tambo_client_provider_1.useTamboClient)();
|
|
20
|
+
const { contextKey } = (0, providers_1.useTamboThread)();
|
|
19
21
|
const { data: queriedProjectId, ...projectIdState } = (0, react_query_hooks_1.useTamboQuery)({
|
|
20
22
|
...options,
|
|
21
23
|
queryKey: ["projectId"],
|
|
@@ -33,7 +35,7 @@ function useTamboThreadList({ projectId, contextKey } = {}, options = {}) {
|
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
37
|
const threadIter = await client.beta.threads.list(currentProjectId, {
|
|
36
|
-
contextKey,
|
|
38
|
+
contextKey: contextKey,
|
|
37
39
|
});
|
|
38
40
|
return threadIter;
|
|
39
41
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":";;AAyBA,gDAiCC;AAxDD,4CAA8C;AAC9C,8EAAoE;AACpE,2DAAoD;AAUpD;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CAChC,EAAE,SAAS,KAA+B,EAAE,EAC5C,UAEI,EAAE;IAEN,MAAM,MAAM,GAAG,IAAA,sCAAc,GAAE,CAAC;IAChC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,0BAAc,GAAE,CAAC;IACxC,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,IAAA,iCAAa,EAAC;QAClE,GAAI,OAA8C;QAClD,QAAQ,EAAE,CAAC,WAAW,CAAC;QACvB,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,SAAS,IAAI,gBAAgB,CAAC;IAEvD,MAAM,WAAW,GAAG,IAAA,iCAAa,EAAC;QAChC,GAAG,OAAO;QACV,OAAO,EAAE,CAAC,CAAC,gBAAgB;QAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,CAAC;QACnD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAClE,UAAU,EAAE,UAAU;aACvB,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { UseQueryOptions } from \"@tanstack/react-query\";\nimport { useTamboThread } from \"../providers\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTamboQuery } from \"./react-query-hooks\";\n\ninterface UseTamboThreadListConfig {\n /**\n * The projectId to get the threads for. If not provided, the current project\n * will be used.\n */\n projectId?: string;\n}\n\n/**\n * Get all the threads for the specified project.\n *\n * If contextKey is empty, then all threads for the project will be returned.\n * If contextKey is not empty, then only the threads for the specified context\n * key will be returned. The contextKey is obtained from the TamboThreadProvider\n * via useTamboThread().\n * @param config - The config for the useTamboThreadList hook\n * @param config.projectId - The projectId to get the threads for\n * @returns The threads for the specified project and optional context key\n */\nexport function useTamboThreadList(\n { projectId }: UseTamboThreadListConfig = {},\n options: Partial<\n UseQueryOptions<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null>\n > = {},\n) {\n const client = useTamboClient();\n const { contextKey } = useTamboThread();\n const { data: queriedProjectId, ...projectIdState } = useTamboQuery({\n ...(options as unknown as UseQueryOptions<string>),\n queryKey: [\"projectId\"],\n queryFn: async () => {\n return (await client.beta.projects.getCurrent()).id;\n },\n });\n const currentProjectId = projectId ?? queriedProjectId;\n\n const threadState = useTamboQuery({\n ...options,\n enabled: !!currentProjectId,\n queryKey: [\"threads\", currentProjectId, contextKey],\n queryFn: async () => {\n if (!currentProjectId) {\n return null;\n }\n const threadIter = await client.beta.threads.list(currentProjectId, {\n contextKey: contextKey,\n });\n return threadIter;\n },\n });\n\n return currentProjectId ? threadState : { data: null, ...projectIdState };\n}\n"]}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_query_1 = require("@tanstack/react-query");
|
|
4
4
|
const react_1 = require("@testing-library/react");
|
|
5
|
+
const providers_1 = require("../providers");
|
|
5
6
|
const tambo_client_provider_1 = require("../providers/tambo-client-provider");
|
|
6
7
|
const use_tambo_threads_1 = require("./use-tambo-threads");
|
|
7
8
|
jest.mock("../providers/tambo-client-provider", () => ({
|
|
8
9
|
useTamboClient: jest.fn(),
|
|
9
10
|
useTamboQueryClient: jest.fn(),
|
|
10
11
|
}));
|
|
12
|
+
jest.mock("../providers", () => ({
|
|
13
|
+
useTamboThread: jest.fn(),
|
|
14
|
+
}));
|
|
11
15
|
describe("useTamboThreadList", () => {
|
|
12
16
|
const mockThreads = [
|
|
13
17
|
{ id: "thread-1", title: "Thread 1" },
|
|
@@ -50,6 +54,9 @@ describe("useTamboThreadList", () => {
|
|
|
50
54
|
};
|
|
51
55
|
beforeEach(() => {
|
|
52
56
|
jest.mocked(tambo_client_provider_1.useTamboQueryClient).mockReturnValue(new react_query_1.QueryClient());
|
|
57
|
+
jest
|
|
58
|
+
.mocked(providers_1.useTamboThread)
|
|
59
|
+
.mockReturnValue({ contextKey: undefined });
|
|
53
60
|
});
|
|
54
61
|
it("should fetch threads for current project when no projectId is provided", async () => {
|
|
55
62
|
const mockClient = jest.mocked(tambo_client_provider_1.useTamboClient);
|
|
@@ -91,7 +98,10 @@ describe("useTamboThreadList", () => {
|
|
|
91
98
|
});
|
|
92
99
|
expect(mockList).toHaveBeenCalledWith("custom-project", {});
|
|
93
100
|
});
|
|
94
|
-
it("should fetch threads with contextKey when provided", async () => {
|
|
101
|
+
it("should fetch threads with contextKey when provided via TamboThreadProvider", async () => {
|
|
102
|
+
jest
|
|
103
|
+
.mocked(providers_1.useTamboThread)
|
|
104
|
+
.mockReturnValue({ contextKey: "test-context" });
|
|
95
105
|
const mockList = jest.fn().mockResolvedValue(mockThreads);
|
|
96
106
|
const mockClient = jest.mocked(tambo_client_provider_1.useTamboClient);
|
|
97
107
|
mockClient.mockReturnValue({
|
|
@@ -108,7 +118,7 @@ describe("useTamboThreadList", () => {
|
|
|
108
118
|
},
|
|
109
119
|
},
|
|
110
120
|
});
|
|
111
|
-
const { result } = (0, react_1.renderHook)(() => (0, use_tambo_threads_1.useTamboThreadList)(
|
|
121
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_tambo_threads_1.useTamboThreadList)());
|
|
112
122
|
await (0, react_1.waitFor)(() => {
|
|
113
123
|
expect(result.current.data).toEqual(mockThreads);
|
|
114
124
|
});
|
|
@@ -1 +1 @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EAAE,CAAC,CACzC,CAAC;QAEF,MAAM,IAAA,eAAO,EAAC,GAAG,EAAE;YACjB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YACrD,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { renderHook, waitFor } from \"@testing-library/react\";\nimport { DeepPartial } from \"ts-essentials\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../providers/tambo-client-provider\";\nimport { PartialTamboAI } from \"../testing/types\";\nimport { useTamboThreadList } from \"./use-tambo-threads\";\n\njest.mock(\"../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\ndescribe(\"useTamboThreadList\", () => {\n const mockThreads = [\n { id: \"thread-1\", title: \"Thread 1\" },\n { id: \"thread-2\", title: \"Thread 2\" },\n ];\n\n const mockProjects = {\n getCurrent: jest.fn(),\n retrieve: jest.fn(),\n delete: jest.fn(),\n } satisfies Partial<TamboAI[\"beta\"][\"projects\"]>;\n\n const mockThreadsApi = {\n list: jest.fn(),\n messages: {\n list: jest.fn(),\n create: jest.fn(),\n delete: jest.fn(),\n updateComponentState: jest.fn(),\n },\n suggestions: {\n list: jest.fn(),\n generate: jest.fn(),\n },\n create: jest.fn(),\n retrieve: jest.fn(),\n update: jest.fn(),\n delete: jest.fn(),\n advance: jest.fn(),\n advanceByID: jest.fn(),\n } satisfies DeepPartial<TamboAI[\"beta\"][\"threads\"]>;\n\n const mockBeta = {\n projects: mockProjects,\n threads: mockThreadsApi,\n registry: {\n retrieve: jest.fn(),\n },\n } satisfies PartialTamboAI[\"beta\"];\n\n const mockTamboAI = {\n apiKey: \"\",\n beta: mockBeta,\n } satisfies PartialTamboAI as unknown as TamboAI;\n\n beforeEach(() => {\n jest.mocked(useTamboQueryClient).mockReturnValue(new QueryClient());\n });\n\n it(\"should fetch threads for current project when no projectId is provided\", async () => {\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockResolvedValue(mockThreads),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() => useTamboThreadList());\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n });\n\n it(\"should fetch threads for specified projectId\", async () => {\n const mockList = jest.fn().mockResolvedValue(mockThreads);\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n threads: {\n ...mockThreadsApi,\n list: mockList,\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({ projectId: \"custom-project\" }),\n );\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n\n expect(mockList).toHaveBeenCalledWith(\"custom-project\", {});\n });\n\n it(\"should fetch threads with contextKey when provided\", async () => {\n const mockList = jest.fn().mockResolvedValue(mockThreads);\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: mockList,\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({ contextKey: \"test-context\" }),\n );\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n\n expect(mockList).toHaveBeenCalledWith(\"current-project\", {\n contextKey: \"test-context\",\n });\n });\n\n it(\"should handle loading state\", async () => {\n let resolvePromise: (value: any) => void;\n const promise = new Promise((resolve) => {\n resolvePromise = resolve;\n });\n\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockReturnValue(promise),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({}, { retry: false }),\n );\n\n expect(result.current).toMatchInlineSnapshot(`\n {\n \"data\": null,\n \"dataUpdatedAt\": 0,\n \"error\": null,\n \"errorUpdateCount\": 0,\n \"errorUpdatedAt\": 0,\n \"failureCount\": 0,\n \"failureReason\": null,\n \"fetchStatus\": \"fetching\",\n \"isEnabled\": true,\n \"isError\": false,\n \"isFetched\": false,\n \"isFetchedAfterMount\": false,\n \"isFetching\": true,\n \"isInitialLoading\": true,\n \"isLoading\": true,\n \"isLoadingError\": false,\n \"isPaused\": false,\n \"isPending\": true,\n \"isPlaceholderData\": false,\n \"isRefetchError\": false,\n \"isRefetching\": false,\n \"isStale\": true,\n \"isSuccess\": false,\n \"promise\": Promise {},\n \"refetch\": [Function],\n \"status\": \"pending\",\n }\n `);\n\n resolvePromise!(mockThreads);\n await waitFor(() => {\n expect(result.current.isLoading).toBe(false);\n });\n });\n\n it(\"should handle error state\", async () => {\n const mockError = new Error(\"Failed to fetch threads\");\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockImplementation(async () => {\n // console.log(\"Mocking error\", mockCount++);\n throw mockError;\n }),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({}, { retry: false }),\n );\n\n await waitFor(() => {\n const { isLoading, error, isError } = result.current;\n expect(isLoading).toBe(false);\n expect(isError).toBe(true);\n expect(error).toBe(mockError);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.test.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.test.tsx"],"names":[],"mappings":";;AACA,uDAAoD;AACpD,kDAA6D;AAE7D,4CAA8C;AAC9C,8EAG4C;AAE5C,2DAAyD;AAEzD,IAAI,CAAC,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE,CAAC,CAAC;IACrD,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC/B,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;CAC1B,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,MAAM,WAAW,GAAG;QAClB,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;QACrC,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;KACtC,CAAC;IAEF,MAAM,YAAY,GAAG;QACnB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;QACrB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACnB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;KAC6B,CAAC;IAEjD,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,QAAQ,EAAE;YACR,IAAI,EAAE,IAAI,CAA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CAAC;QAC/C,UAAU,CAAC,eAAe,CAAC;YACzB,GAAG,WAAW;YACd,IAAI,EAAE;gBACJ,GAAG,QAAQ;gBACX,QAAQ,EAAE;oBACR,GAAG,YAAY;oBACf,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,iBAAiB,EAAE,CAAC;iBACnE;gBACD,OAAO,EAAE;oBACP,GAAG,cAAc;oBACjB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;wBAC5C,6CAA6C;wBAC7C,MAAM,SAAS,CAAC;oBAClB,CAAC,CAAC;iBACH;aACF;SAC8B,CAAC,CAAC;QAEnC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CACjC,IAAA,sCAAkB,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CACzC,CAAC;QAEF,MAAM,IAAA,eAAO,EAAC,GAAG,EAAE;YACjB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YACrD,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { renderHook, waitFor } from \"@testing-library/react\";\nimport { DeepPartial } from \"ts-essentials\";\nimport { useTamboThread } from \"../providers\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../providers/tambo-client-provider\";\nimport { PartialTamboAI } from \"../testing/types\";\nimport { useTamboThreadList } from \"./use-tambo-threads\";\n\njest.mock(\"../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\njest.mock(\"../providers\", () => ({\n useTamboThread: jest.fn(),\n}));\n\ndescribe(\"useTamboThreadList\", () => {\n const mockThreads = [\n { id: \"thread-1\", title: \"Thread 1\" },\n { id: \"thread-2\", title: \"Thread 2\" },\n ];\n\n const mockProjects = {\n getCurrent: jest.fn(),\n retrieve: jest.fn(),\n delete: jest.fn(),\n } satisfies Partial<TamboAI[\"beta\"][\"projects\"]>;\n\n const mockThreadsApi = {\n list: jest.fn(),\n messages: {\n list: jest.fn(),\n create: jest.fn(),\n delete: jest.fn(),\n updateComponentState: jest.fn(),\n },\n suggestions: {\n list: jest.fn(),\n generate: jest.fn(),\n },\n create: jest.fn(),\n retrieve: jest.fn(),\n update: jest.fn(),\n delete: jest.fn(),\n advance: jest.fn(),\n advanceByID: jest.fn(),\n } satisfies DeepPartial<TamboAI[\"beta\"][\"threads\"]>;\n\n const mockBeta = {\n projects: mockProjects,\n threads: mockThreadsApi,\n registry: {\n retrieve: jest.fn(),\n },\n } satisfies PartialTamboAI[\"beta\"];\n\n const mockTamboAI = {\n apiKey: \"\",\n beta: mockBeta,\n } satisfies PartialTamboAI as unknown as TamboAI;\n\n beforeEach(() => {\n jest.mocked(useTamboQueryClient).mockReturnValue(new QueryClient());\n jest\n .mocked(useTamboThread)\n .mockReturnValue({ contextKey: undefined } as any);\n });\n\n it(\"should fetch threads for current project when no projectId is provided\", async () => {\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockResolvedValue(mockThreads),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() => useTamboThreadList());\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n });\n\n it(\"should fetch threads for specified projectId\", async () => {\n const mockList = jest.fn().mockResolvedValue(mockThreads);\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n threads: {\n ...mockThreadsApi,\n list: mockList,\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({ projectId: \"custom-project\" }),\n );\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n\n expect(mockList).toHaveBeenCalledWith(\"custom-project\", {});\n });\n\n it(\"should fetch threads with contextKey when provided via TamboThreadProvider\", async () => {\n jest\n .mocked(useTamboThread)\n .mockReturnValue({ contextKey: \"test-context\" } as any);\n const mockList = jest.fn().mockResolvedValue(mockThreads);\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: mockList,\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() => useTamboThreadList());\n\n await waitFor(() => {\n expect(result.current.data).toEqual(mockThreads);\n });\n\n expect(mockList).toHaveBeenCalledWith(\"current-project\", {\n contextKey: \"test-context\",\n });\n });\n\n it(\"should handle loading state\", async () => {\n let resolvePromise: (value: any) => void;\n const promise = new Promise((resolve) => {\n resolvePromise = resolve;\n });\n\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockReturnValue(promise),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({}, { retry: false }),\n );\n\n expect(result.current).toMatchInlineSnapshot(`\n {\n \"data\": null,\n \"dataUpdatedAt\": 0,\n \"error\": null,\n \"errorUpdateCount\": 0,\n \"errorUpdatedAt\": 0,\n \"failureCount\": 0,\n \"failureReason\": null,\n \"fetchStatus\": \"fetching\",\n \"isEnabled\": true,\n \"isError\": false,\n \"isFetched\": false,\n \"isFetchedAfterMount\": false,\n \"isFetching\": true,\n \"isInitialLoading\": true,\n \"isLoading\": true,\n \"isLoadingError\": false,\n \"isPaused\": false,\n \"isPending\": true,\n \"isPlaceholderData\": false,\n \"isRefetchError\": false,\n \"isRefetching\": false,\n \"isStale\": true,\n \"isSuccess\": false,\n \"promise\": Promise {},\n \"refetch\": [Function],\n \"status\": \"pending\",\n }\n `);\n\n resolvePromise!(mockThreads);\n await waitFor(() => {\n expect(result.current.isLoading).toBe(false);\n });\n });\n\n it(\"should handle error state\", async () => {\n const mockError = new Error(\"Failed to fetch threads\");\n const mockClient = jest.mocked(useTamboClient);\n mockClient.mockReturnValue({\n ...mockTamboAI,\n beta: {\n ...mockBeta,\n projects: {\n ...mockProjects,\n getCurrent: jest.fn().mockResolvedValue({ id: \"current-project\" }),\n },\n threads: {\n ...mockThreadsApi,\n list: jest.fn().mockImplementation(async () => {\n // console.log(\"Mocking error\", mockCount++);\n throw mockError;\n }),\n },\n },\n } satisfies PartialTamboAI as any);\n\n const { result } = renderHook(() =>\n useTamboThreadList({}, { retry: false }),\n );\n\n await waitFor(() => {\n const { isLoading, error, isError } = result.current;\n expect(isLoading).toBe(false);\n expect(isError).toBe(true);\n expect(error).toBe(mockError);\n });\n });\n});\n"]}
|
|
@@ -5,7 +5,6 @@ import { TamboComponentContextProps } from "./tambo-component-provider";
|
|
|
5
5
|
import { ContextAttachmentState, TamboContextAttachmentProviderProps } from "./tambo-context-attachment-provider";
|
|
6
6
|
import { TamboContextHelpersContextProps, TamboContextHelpersProviderProps } from "./tambo-context-helpers-provider";
|
|
7
7
|
import { TamboRegistryProviderProps } from "./tambo-registry-provider";
|
|
8
|
-
import { TamboThreadInputProviderProps } from "./tambo-thread-input-provider";
|
|
9
8
|
import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadProviderProps } from "./tambo-thread-provider";
|
|
10
9
|
/**
|
|
11
10
|
* The TamboProvider gives full access to the whole Tambo API. This includes the
|
|
@@ -29,7 +28,7 @@ import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadP
|
|
|
29
28
|
* @param props.getContextHelperData - Optional function to customize the data sent to the AI for each context attachment
|
|
30
29
|
* @returns The TamboProvider component
|
|
31
30
|
*/
|
|
32
|
-
export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps & TamboContextHelpersProviderProps &
|
|
31
|
+
export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps & TamboContextHelpersProviderProps & Partial<Pick<TamboContextAttachmentProviderProps, "getContextHelperData">>>>;
|
|
33
32
|
export type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboGenerationStageContextProps & TamboComponentContextProps & TamboInteractableContext & TamboContextHelpersContextProps & ContextAttachmentState;
|
|
34
33
|
export declare const TamboContext: React.Context<TamboContextProps>;
|
|
35
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAEL,uBAAuB,EAEvB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EAEtB,mCAAmC,EAEpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,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;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
|
|
@@ -67,13 +67,13 @@ const tambo_thread_provider_1 = require("./tambo-thread-provider");
|
|
|
67
67
|
* @param props.getContextHelperData - Optional function to customize the data sent to the AI for each context attachment
|
|
68
68
|
* @returns The TamboProvider component
|
|
69
69
|
*/
|
|
70
|
-
const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, mcpServers, streaming, autoGenerateThreadName, autoGenerateNameThreshold, contextHelpers, contextKey, initialMessages, onCallUnregisteredTool, getContextHelperData, }) => {
|
|
70
|
+
const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, mcpServers, streaming, autoGenerateThreadName, autoGenerateNameThreshold, contextHelpers, contextKey, initialMessages, onCallUnregisteredTool, getContextHelperData, getResource, listResources, resources, }) => {
|
|
71
71
|
return (react_1.default.createElement(tambo_client_provider_1.TamboClientProvider, { tamboUrl: tamboUrl, apiKey: apiKey, environment: environment, userToken: userToken },
|
|
72
|
-
react_1.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, { components: components, tools: tools, mcpServers: mcpServers, onCallUnregisteredTool: onCallUnregisteredTool },
|
|
72
|
+
react_1.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, { components: components, tools: tools, mcpServers: mcpServers, onCallUnregisteredTool: onCallUnregisteredTool, getResource: getResource, listResources: listResources, resources: resources },
|
|
73
73
|
react_1.default.createElement(tambo_context_helpers_provider_1.TamboContextHelpersProvider, { contextHelpers: contextHelpers },
|
|
74
|
-
react_1.default.createElement(tambo_thread_provider_1.TamboThreadProvider, { streaming: streaming, autoGenerateThreadName: autoGenerateThreadName, autoGenerateNameThreshold: autoGenerateNameThreshold, initialMessages: initialMessages },
|
|
74
|
+
react_1.default.createElement(tambo_thread_provider_1.TamboThreadProvider, { contextKey: contextKey, streaming: streaming, autoGenerateThreadName: autoGenerateThreadName, autoGenerateNameThreshold: autoGenerateNameThreshold, initialMessages: initialMessages },
|
|
75
75
|
react_1.default.createElement(tambo_mcp_token_provider_1.TamboMcpTokenProvider, null,
|
|
76
|
-
react_1.default.createElement(tambo_thread_input_provider_1.TamboThreadInputProvider,
|
|
76
|
+
react_1.default.createElement(tambo_thread_input_provider_1.TamboThreadInputProvider, null,
|
|
77
77
|
react_1.default.createElement(tambo_context_attachment_provider_1.TamboContextAttachmentProvider, { getContextHelperData: getContextHelperData },
|
|
78
78
|
react_1.default.createElement(tambo_component_provider_1.TamboComponentProvider, null,
|
|
79
79
|
react_1.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAE5E,mEAKiC;AACjC,yEAIoC;AACpC,2FAK6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAE5E,mEAKiC;AACjC,yEAIoC;AACpC,2FAK6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+EAAyE;AACzE,mEAMiC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,MAAM,aAAa,GAQtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,a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,WAAW,EAAE,eAAe,EAAE,GAAG,aAAa,CAAC;IAC/D,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAChD,MAAM,iBAAiB,GAAG,IAAA,6DAAyB,GAAE,CAAC;IAEtD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;YACjB,GAAG,iBAAiB;SACrB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,sBAAsB,0BAgCjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContext,\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n ContextAttachmentState,\n TamboContextAttachmentProvider,\n TamboContextAttachmentProviderProps,\n useTamboContextAttachment,\n} from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport { TamboMcpTokenProvider } from \"./tambo-mcp-token-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport { TamboThreadInputProvider } from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.mcpServers - The MCP servers to register (metadata only - use TamboMcpProvider for connections)\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.autoGenerateThreadName - Whether to automatically generate thread names. Defaults to true.\n * @param props.autoGenerateNameThreshold - The message count threshold at which the thread name will be auto-generated. Defaults to 3.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token\n * @param props.contextKey - Optional context key passed to thread input provider for scoping threads\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @param props.initialMessages - Initial messages to be included in new threads\n * @param props.getContextHelperData - Optional function to customize the data sent to the AI for each context attachment\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n Partial<Pick<TamboContextAttachmentProviderProps, \"getContextHelperData\">>\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n mcpServers,\n streaming,\n autoGenerateThreadName,\n autoGenerateNameThreshold,\n contextHelpers,\n contextKey,\n initialMessages,\n onCallUnregisteredTool,\n getContextHelperData,\n getResource,\n listResources,\n resources,\n}) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n getResource={getResource}\n listResources={listResources}\n resources={resources}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider\n contextKey={contextKey}\n streaming={streaming}\n autoGenerateThreadName={autoGenerateThreadName}\n autoGenerateNameThreshold={autoGenerateNameThreshold}\n initialMessages={initialMessages}\n >\n <TamboMcpTokenProvider>\n <TamboThreadInputProvider>\n <TamboContextAttachmentProvider\n getContextHelperData={getContextHelperData}\n >\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>\n {children}\n </TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboThreadInputProvider>\n </TamboMcpTokenProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps &\n ContextAttachmentState;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboCompositeProvider must be used within a TamboClientProvider\",\n );\n }\n const { client, queryClient, isUpdatingToken } = clientContext;\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n const contextAttachment = useTamboContextAttachment();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n ...contextAttachment,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,SAAS,EAET,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,OAAO,EAEL,gCAAgC,EACjC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAQ1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2C;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,CAAC,SAAS,GAAG,uBAAuB,CAAC,EAAE,CAAC;IAChD,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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C,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;CACrE;AA2KD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAwH1C,CAAC"}
|
|
@@ -255,6 +255,7 @@ const TamboStubProvider = ({ children, thread, components = [], tools = [], thre
|
|
|
255
255
|
streaming: overrides.streaming ?? true,
|
|
256
256
|
sendThreadMessage: overrides.sendThreadMessage ?? defaults.sendThreadMessage,
|
|
257
257
|
cancel: overrides.cancel ?? defaults.cancel,
|
|
258
|
+
contextKey,
|
|
258
259
|
};
|
|
259
260
|
const componentContextProps = {
|
|
260
261
|
registerComponent: overrides.registerComponent ?? defaults.registerComponent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,uDAAoD;AACpD,+CAA4D;AAO5D,sFAAuE;AAEvE,mEAA6D;AAC7D,yEAGoC;AACpC,2FAAqF;AACrF,qFAG0C;AAC1C,+EAA0E;AAC1E,qDAG0B;AAC1B,uEAAiE;AACjE,mEAIiC;AAsBjC;;;GAGG;AACH,MAAM,uBAAuB,GASzB,CAAC,EACH,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,eAAe,GAChB,EAAE,EAAE;IACH,4DAA4D;IAC5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,kCAAkC;YAClC,WAAW,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;YAEnD,2FAA2F;YAC3F,WAAW,CAAC,YAAY,CAAC,CAA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client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport {\n TamboComponent,\n TamboTool,\n TamboToolRegistry,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport { TamboContextAttachmentProvider } from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"./tambo-interactable-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageProvider,\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: (TamboTool | TamboToolWithToolSchema)[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n isUpdatingToken: boolean;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({\n children,\n client,\n queryClient,\n threads,\n projectId,\n contextKey,\n isUpdatingToken,\n}) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n }}\n >\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<\n Pick<\n TamboRegistryContext,\n | \"componentList\"\n | \"toolRegistry\"\n | \"componentToolAssociations\"\n | \"registerComponent\"\n | \"registerTool\"\n | \"registerTools\"\n | \"addToolAssociation\"\n >\n >\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer: () => {},\n registerMcpServers: () => {},\n registerResource: () => {},\n registerResources: () => {},\n registerResourceSource: () => {},\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n // Extract generation stage info from the thread\n const generationStage =\n (threadContextProps.thread?.generationStage as GenerationStage) ??\n GenerationStage.IDLE;\n const statusMessage = threadContextProps.thread?.statusMessage ?? \"\";\n\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n <TamboGenerationStageProvider\n generationStage={generationStage}\n statusMessage={statusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce((acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n }, {} as TamboToolRegistry);\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n currentThreadId: thread.id,\n currentThread: thread,\n threadMap: { [thread.id]: thread },\n setThreadMap: () => {},\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n streaming: overrides.streaming ?? true,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n isUpdatingToken={false}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,uDAAoD;AACpD,+CAA4D;AAO5D,sFAAuE;AAEvE,mEAA6D;AAC7D,yEAGoC;AACpC,2FAAqF;AACrF,qFAG0C;AAC1C,+EAA0E;AAC1E,qDAG0B;AAC1B,uEAAiE;AACjE,mEAIiC;AAsBjC;;;GAGG;AACH,MAAM,uBAAuB,GASzB,CAAC,EACH,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,eAAe,GAChB,EAAE,EAAE;IACH,4DAA4D;IAC5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,kCAAkC;YAClC,WAAW,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;YAEnD,2FAA2F;YAC3F,WAAW,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAElD,OAAO,CACL,8BAAC,0CAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;SAChB,IAEA,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,yBAAyB,GAa3B,CAAC,EACH,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,iBAAiB,EACjB,YA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AAC,kBAAkB,IAAI,QAAQ,CAAC,kBAAkB;KAC9D,CAAC;IAEF,OAAO,CACL,8BAAC,uBAAuB,IACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,KAAK;QAEtB,8BAAC,yBAAyB,IACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,yBAAyB,EAAE,yBAAyB,EACpD,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAC1D,YAAY,EAAE,qBAAqB,CAAC,YAAY,EAChD,aAAa,EAAE,qBAAqB,CAAC,aAAa,EAClD,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;YAE5D,8BAAC,uBAAuB,OAAK,kBAAkB;gBAC7C,8BAAC,4DAA2B,IAAC,cAAc,EAAE,cAAc;oBACzD,8BAAC,kEAA8B;wBAC7B,8BAAC,iDAAsB;4BACrB,8BAAC,uDAAyB;gCACxB,8BAAC,uCAAsB,QAAE,QAAQ,CAA0B,CACjC,CACL,CACM,CACL,CACN,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC;AAzHW,QAAA,iBAAiB,qBAyH5B","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport {\n TamboComponent,\n TamboTool,\n TamboToolRegistry,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport { TamboContextAttachmentProvider } from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"./tambo-interactable-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageProvider,\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: (TamboTool | TamboToolWithToolSchema)[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n isUpdatingToken: boolean;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({\n children,\n client,\n queryClient,\n threads,\n projectId,\n contextKey,\n isUpdatingToken,\n}) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n }}\n >\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<\n Pick<\n TamboRegistryContext,\n | \"componentList\"\n | \"toolRegistry\"\n | \"componentToolAssociations\"\n | \"registerComponent\"\n | \"registerTool\"\n | \"registerTools\"\n | \"addToolAssociation\"\n >\n >\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer: () => {},\n registerMcpServers: () => {},\n registerResource: () => {},\n registerResources: () => {},\n registerResourceSource: () => {},\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n // Extract generation stage info from the thread\n const generationStage =\n (threadContextProps.thread?.generationStage as GenerationStage) ??\n GenerationStage.IDLE;\n const statusMessage = threadContextProps.thread?.statusMessage ?? \"\";\n\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n <TamboGenerationStageProvider\n generationStage={generationStage}\n statusMessage={statusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce((acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n }, {} as TamboToolRegistry);\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n currentThreadId: thread.id,\n currentThread: thread,\n threadMap: { [thread.id]: thread },\n setThreadMap: () => {},\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n streaming: overrides.streaming ?? true,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n cancel: overrides.cancel ?? defaults.cancel,\n contextKey,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n isUpdatingToken={false}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
@@ -71,7 +71,7 @@ describe("TamboStubProvider threads functionality", () => {
|
|
|
71
71
|
});
|
|
72
72
|
it("should populate query cache with threads data using contextKey", async () => {
|
|
73
73
|
const wrapper = ({ children }) => (react_2.default.createElement(tambo_stubs_1.TamboStubProvider, { thread: mockThread, threads: mockThreadsData, projectId: "test-project", contextKey: "test-context", components: [], tools: [] }, children));
|
|
74
|
-
const { result } = (0, react_1.renderHook)(() => (0, use_tambo_threads_1.useTamboThreadList)(
|
|
74
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_tambo_threads_1.useTamboThreadList)(), { wrapper });
|
|
75
75
|
// Wait for the effect to run
|
|
76
76
|
await (0, react_2.act)(async () => {
|
|
77
77
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.test.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAAoD;AACpD,+CAAmC;AACnC,kEAAgE;AAEhE,+CAAkD;AAElD,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACvD,MAAM,UAAU,GAAgB;QAC9B,EAAE,EAAE,aAAa;QACjB,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,sBAAsB;QACjC,SAAS,EAAE,cAAc;QACzB,SAAS,EAAE,sBAAsB;QACjC,QAAQ,EAAE,EAAE;KACb,CAAC;IAEF,MAAM,eAAe,GAAwD;QAC3E,KAAK,EAAE,CAAC,UAAU,CAAC;QACnB,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC;QACrC,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7B,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC;IAEF,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE,CAAC,CAC/D,8BAAC,+BAAiB,IAChB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,eAAe,EACxB,SAAS,EAAC,cAAc,EACxB,UAAU,EAAE,EAAE,EACd,KAAK,EAAE,EAAE,IAER,Q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AE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,sCAAkB,GAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACvE,6BAA6B;QAC7B,MAAM,IAAA,WAAG,EAAC,KAAK,IAAI,EAAE;YACnB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,+EAA+E;QAC/E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { renderHook } from \"@testing-library/react\";\nimport React, { act } from \"react\";\nimport { useTamboThreadList } from \"../hooks/use-tambo-threads\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboStubProvider } from \"./tambo-stubs\";\n\ndescribe(\"TamboStubProvider threads functionality\", () => {\n const mockThread: TamboThread = {\n id: \"test-thread\",\n messages: [],\n createdAt: \"2024-01-01T00:00:00Z\",\n projectId: \"test-project\",\n updatedAt: \"2024-01-01T00:00:00Z\",\n metadata: {},\n };\n\n const mockThreadsData: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit> = {\n items: [mockThread],\n total: 1,\n count: 1,\n getPaginatedItems: () => [mockThread],\n nextPageRequestOptions: () => ({\n offset: 1,\n limit: 10,\n path: \"/threads\",\n method: \"get\",\n }),\n };\n\n it(\"should populate query cache with threads data\", async () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboStubProvider\n thread={mockThread}\n threads={mockThreadsData}\n projectId=\"test-project\"\n components={[]}\n tools={[]}\n >\n {children}\n </TamboStubProvider>\n );\n\n const { result } = renderHook(() => useTamboThreadList(), { wrapper });\n // Wait for the effect to run\n await act(async () => {\n await new Promise((resolve) => setTimeout(resolve, 0));\n });\n\n // The hook should return the pre-populated threads data\n expect(result.current.data).toEqual(mockThreadsData);\n expect(result.current.isLoading).toBe(false);\n });\n\n it(\"should populate query cache with threads data using contextKey\", async () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboStubProvider\n thread={mockThread}\n threads={mockThreadsData}\n projectId=\"test-project\"\n contextKey=\"test-context\"\n components={[]}\n tools={[]}\n >\n {children}\n </TamboStubProvider>\n );\n\n const { result } = renderHook(() => useTamboThreadList(), { wrapper });\n // Wait for the effect to run\n await act(async () => {\n await new Promise((resolve) => setTimeout(resolve, 0));\n });\n\n // The hook should return the pre-populated threads data for the specific context\n expect(result.current.data).toEqual(mockThreadsData);\n expect(result.current.isLoading).toBe(false);\n });\n\n it(\"should default projectId to thread.projectId when not provided\", async () => {\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboStubProvider\n thread={mockThread}\n threads={mockThreadsData}\n // No explicit projectId provided - should use thread.projectId\n components={[]}\n tools={[]}\n >\n {children}\n </TamboStubProvider>\n );\n\n const { result } = renderHook(() => useTamboThreadList(), { wrapper });\n // Wait for the effect to run\n await act(async () => {\n await new Promise((resolve) => setTimeout(resolve, 0));\n });\n\n // The hook should return the pre-populated threads data using thread.projectId\n expect(result.current.data).toEqual(mockThreadsData);\n expect(result.current.isLoading).toBe(false);\n });\n});\n"]}
|
|
@@ -30,7 +30,6 @@ export interface TamboThreadInputContextProps extends Omit<UseTamboMutationResul
|
|
|
30
30
|
* @param options - Submission options
|
|
31
31
|
*/
|
|
32
32
|
submit: (options?: {
|
|
33
|
-
contextKey?: string;
|
|
34
33
|
streamResponse?: boolean;
|
|
35
34
|
forceToolChoice?: string;
|
|
36
35
|
additionalContext?: Record<string, any>;
|
|
@@ -48,19 +47,15 @@ export interface TamboThreadInputContextProps extends Omit<UseTamboMutationResul
|
|
|
48
47
|
clearImages: () => void;
|
|
49
48
|
}
|
|
50
49
|
export declare const TamboThreadInputContext: React.Context<TamboThreadInputContextProps | undefined>;
|
|
51
|
-
export interface TamboThreadInputProviderProps {
|
|
52
|
-
contextKey?: string;
|
|
53
|
-
}
|
|
54
50
|
/**
|
|
55
51
|
* Provider that manages shared thread input state across all components
|
|
56
52
|
* This ensures that useTamboThreadInput, useTamboSuggestions, and components
|
|
57
53
|
* all share the same input state
|
|
58
54
|
* @param props - The props for the TamboThreadInputProvider
|
|
59
|
-
* @param props.contextKey - Optional context key.
|
|
60
55
|
* @param props.children - The children to render.
|
|
61
56
|
* @returns The thread input context
|
|
62
57
|
*/
|
|
63
|
-
export declare const TamboThreadInputProvider: React.FC<PropsWithChildren
|
|
58
|
+
export declare const TamboThreadInputProvider: React.FC<PropsWithChildren>;
|
|
64
59
|
/**
|
|
65
60
|
* Hook to access the shared thread input state
|
|
66
61
|
* contextKey parameter is not passed here anymore. Instead, use the contextKey prop in the TamboProvider.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAoB,MAAM,6BAA6B,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CACxD,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,GACD,SAAS,CACZ,EACD,QAAQ,GAAG,aAAa,CACzB;IACC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,
|
|
1
|
+
{"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAoB,MAAM,6BAA6B,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CACxD,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,GACD,SAAS,CACZ,EACD,QAAQ,GAAG,aAAa,CACzB;IACC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACxC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACxC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpB,8BAA8B;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,yBAAyB;IACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,0BAA0B;IAC1B,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,4BAA4B;IAC5B,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,8BAA8B;IAC9B,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,yDAExB,CAAC;AAEb;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4IhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oCAS/B,CAAC"}
|
|
@@ -59,15 +59,14 @@ exports.TamboThreadInputContext = (0, react_1.createContext)(undefined);
|
|
|
59
59
|
* This ensures that useTamboThreadInput, useTamboSuggestions, and components
|
|
60
60
|
* all share the same input state
|
|
61
61
|
* @param props - The props for the TamboThreadInputProvider
|
|
62
|
-
* @param props.contextKey - Optional context key.
|
|
63
62
|
* @param props.children - The children to render.
|
|
64
63
|
* @returns The thread input context
|
|
65
64
|
*/
|
|
66
|
-
const TamboThreadInputProvider = ({ children,
|
|
67
|
-
const { thread, sendThreadMessage } = (0, tambo_thread_provider_1.useTamboThread)();
|
|
65
|
+
const TamboThreadInputProvider = ({ children, }) => {
|
|
66
|
+
const { thread, sendThreadMessage, contextKey } = (0, tambo_thread_provider_1.useTamboThread)();
|
|
68
67
|
const [inputValue, setInputValue] = (0, react_1.useState)("");
|
|
69
68
|
const imageState = (0, use_message_images_1.useMessageImages)();
|
|
70
|
-
const submit = (0, react_1.useCallback)(async ({
|
|
69
|
+
const submit = (0, react_1.useCallback)(async ({ streamResponse, forceToolChoice, additionalContext, resourceNames = {}, } = {}) => {
|
|
71
70
|
// Validate text input if present
|
|
72
71
|
if (inputValue?.trim()) {
|
|
73
72
|
const validation = (0, validate_input_1.validateInput)(inputValue);
|
|
@@ -86,7 +85,7 @@ const TamboThreadInputProvider = ({ children, contextKey }) => {
|
|
|
86
85
|
try {
|
|
87
86
|
await sendThreadMessage(inputValue || "Image message", {
|
|
88
87
|
threadId: thread.id,
|
|
89
|
-
contextKey
|
|
88
|
+
contextKey,
|
|
90
89
|
streamResponse: streamResponse,
|
|
91
90
|
forceToolChoice: forceToolChoice,
|
|
92
91
|
additionalContext: additionalContext,
|