@tambo-ai/react 0.71.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
  2. package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
  3. package/dist/v1/hooks/use-tambo-v1-component-state.js +134 -0
  4. package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
  5. package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
  6. package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
  7. package/dist/v1/hooks/use-tambo-v1-component-state.test.js +292 -0
  8. package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
  9. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +62 -0
  10. package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
  11. package/dist/v1/hooks/use-tambo-v1-thread-input.js +76 -0
  12. package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
  13. package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
  14. package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
  15. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +168 -0
  16. package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
  17. package/dist/v1/index.d.ts +23 -12
  18. package/dist/v1/index.d.ts.map +1 -1
  19. package/dist/v1/index.js +48 -14
  20. package/dist/v1/index.js.map +1 -1
  21. package/dist/v1/providers/tambo-v1-provider.d.ts +43 -1
  22. package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  23. package/dist/v1/providers/tambo-v1-provider.js +24 -3
  24. package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
  25. package/dist/v1/providers/tambo-v1-provider.test.js +58 -0
  26. package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
  27. package/dist/v1/types/message.d.ts +27 -2
  28. package/dist/v1/types/message.d.ts.map +1 -1
  29. package/dist/v1/types/message.js.map +1 -1
  30. package/dist/v1/utils/component-renderer.d.ts +89 -0
  31. package/dist/v1/utils/component-renderer.d.ts.map +1 -0
  32. package/dist/v1/utils/component-renderer.js +216 -0
  33. package/dist/v1/utils/component-renderer.js.map +1 -0
  34. package/dist/v1/utils/component-renderer.test.d.ts +2 -0
  35. package/dist/v1/utils/component-renderer.test.d.ts.map +1 -0
  36. package/dist/v1/utils/component-renderer.test.js +380 -0
  37. package/dist/v1/utils/component-renderer.test.js.map +1 -0
  38. package/dist/v1/utils/event-accumulator.js +28 -8
  39. package/dist/v1/utils/event-accumulator.js.map +1 -1
  40. package/dist/v1/utils/event-accumulator.test.js +201 -6
  41. package/dist/v1/utils/event-accumulator.test.js.map +1 -1
  42. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
  43. package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
  44. package/esm/v1/hooks/use-tambo-v1-component-state.js +131 -0
  45. package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
  46. package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
  47. package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
  48. package/esm/v1/hooks/use-tambo-v1-component-state.test.js +290 -0
  49. package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
  50. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +62 -0
  51. package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
  52. package/esm/v1/hooks/use-tambo-v1-thread-input.js +73 -0
  53. package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
  54. package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
  55. package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
  56. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +166 -0
  57. package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
  58. package/esm/v1/index.d.ts +23 -12
  59. package/esm/v1/index.d.ts.map +1 -1
  60. package/esm/v1/index.js +31 -12
  61. package/esm/v1/index.js.map +1 -1
  62. package/esm/v1/providers/tambo-v1-provider.d.ts +43 -1
  63. package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
  64. package/esm/v1/providers/tambo-v1-provider.js +24 -4
  65. package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
  66. package/esm/v1/providers/tambo-v1-provider.test.js +59 -1
  67. package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
  68. package/esm/v1/types/message.d.ts +27 -2
  69. package/esm/v1/types/message.d.ts.map +1 -1
  70. package/esm/v1/types/message.js.map +1 -1
  71. package/esm/v1/utils/component-renderer.d.ts +89 -0
  72. package/esm/v1/utils/component-renderer.d.ts.map +1 -0
  73. package/esm/v1/utils/component-renderer.js +175 -0
  74. package/esm/v1/utils/component-renderer.js.map +1 -0
  75. package/esm/v1/utils/component-renderer.test.d.ts +2 -0
  76. package/esm/v1/utils/component-renderer.test.d.ts.map +1 -0
  77. package/esm/v1/utils/component-renderer.test.js +375 -0
  78. package/esm/v1/utils/component-renderer.test.js.map +1 -0
  79. package/esm/v1/utils/event-accumulator.js +28 -8
  80. package/esm/v1/utils/event-accumulator.js.map +1 -1
  81. package/esm/v1/utils/event-accumulator.test.js +201 -6
  82. package/esm/v1/utils/event-accumulator.test.js.map +1 -1
  83. package/package.json +1 -1
@@ -0,0 +1,166 @@
1
+ import { renderHook, act } from "@testing-library/react";
2
+ import { useTamboV1ThreadInput } from "./use-tambo-v1-thread-input";
3
+ // Create mock functions
4
+ const mockMutateAsync = jest.fn();
5
+ const mockMutate = jest.fn();
6
+ const mockReset = jest.fn();
7
+ // Mock useTamboV1SendMessage module
8
+ jest.mock("./use-tambo-v1-send-message");
9
+ import { useTamboV1SendMessage } from "./use-tambo-v1-send-message";
10
+ // Helper to set up the mock with default values
11
+ function setupMock(overrides = {}) {
12
+ const mockReturn = {
13
+ mutateAsync: mockMutateAsync,
14
+ mutate: mockMutate,
15
+ isPending: false,
16
+ isError: false,
17
+ error: null,
18
+ isSuccess: false,
19
+ isIdle: true,
20
+ isPaused: false,
21
+ status: "idle",
22
+ data: undefined,
23
+ variables: undefined,
24
+ failureCount: 0,
25
+ failureReason: null,
26
+ reset: mockReset,
27
+ context: undefined,
28
+ submittedAt: 0,
29
+ ...overrides,
30
+ };
31
+ jest.mocked(useTamboV1SendMessage).mockReturnValue(mockReturn);
32
+ return mockReturn;
33
+ }
34
+ describe("useTamboV1ThreadInput", () => {
35
+ beforeEach(() => {
36
+ jest.clearAllMocks();
37
+ mockMutateAsync.mockResolvedValue({ threadId: "thread_123" });
38
+ setupMock();
39
+ });
40
+ describe("State Management", () => {
41
+ it("initializes with empty value", () => {
42
+ const { result } = renderHook(() => useTamboV1ThreadInput());
43
+ expect(result.current.value).toBe("");
44
+ });
45
+ it("updates value via setValue", () => {
46
+ const { result } = renderHook(() => useTamboV1ThreadInput());
47
+ act(() => {
48
+ result.current.setValue("Hello world");
49
+ });
50
+ expect(result.current.value).toBe("Hello world");
51
+ });
52
+ it("supports functional updates for setValue", () => {
53
+ const { result } = renderHook(() => useTamboV1ThreadInput());
54
+ act(() => {
55
+ result.current.setValue("Hello");
56
+ });
57
+ act(() => {
58
+ result.current.setValue((prev) => `${prev} world`);
59
+ });
60
+ expect(result.current.value).toBe("Hello world");
61
+ });
62
+ });
63
+ describe("Submit Behavior", () => {
64
+ it("submits message and clears input on success", async () => {
65
+ const { result } = renderHook(() => useTamboV1ThreadInput("thread_123"));
66
+ act(() => {
67
+ result.current.setValue("Test message");
68
+ });
69
+ await act(async () => {
70
+ const response = await result.current.submit();
71
+ expect(response.threadId).toBe("thread_123");
72
+ });
73
+ // Input should be cleared
74
+ expect(result.current.value).toBe("");
75
+ // Should have called mutateAsync with correct message format
76
+ expect(mockMutateAsync).toHaveBeenCalledWith({
77
+ message: {
78
+ role: "user",
79
+ content: [{ type: "text", text: "Test message" }],
80
+ },
81
+ debug: undefined,
82
+ });
83
+ });
84
+ it("throws error when submitting empty message", async () => {
85
+ const { result } = renderHook(() => useTamboV1ThreadInput());
86
+ await expect(result.current.submit()).rejects.toThrow("Message cannot be empty");
87
+ expect(mockMutateAsync).not.toHaveBeenCalled();
88
+ });
89
+ it("throws error when submitting whitespace-only message", async () => {
90
+ const { result } = renderHook(() => useTamboV1ThreadInput());
91
+ act(() => {
92
+ result.current.setValue(" ");
93
+ });
94
+ await expect(result.current.submit()).rejects.toThrow("Message cannot be empty");
95
+ expect(mockMutateAsync).not.toHaveBeenCalled();
96
+ });
97
+ it("passes debug option to mutation", async () => {
98
+ const { result } = renderHook(() => useTamboV1ThreadInput());
99
+ act(() => {
100
+ result.current.setValue("Debug message");
101
+ });
102
+ await act(async () => {
103
+ await result.current.submit({ debug: true });
104
+ });
105
+ expect(mockMutateAsync).toHaveBeenCalledWith({
106
+ message: {
107
+ role: "user",
108
+ content: [{ type: "text", text: "Debug message" }],
109
+ },
110
+ debug: true,
111
+ });
112
+ });
113
+ it("trims whitespace from message", async () => {
114
+ const { result } = renderHook(() => useTamboV1ThreadInput());
115
+ act(() => {
116
+ result.current.setValue(" Trimmed message ");
117
+ });
118
+ await act(async () => {
119
+ await result.current.submit();
120
+ });
121
+ expect(mockMutateAsync).toHaveBeenCalledWith({
122
+ message: {
123
+ role: "user",
124
+ content: [{ type: "text", text: "Trimmed message" }],
125
+ },
126
+ debug: undefined,
127
+ });
128
+ });
129
+ });
130
+ describe("Thread ID Handling", () => {
131
+ it("passes threadId to useTamboV1SendMessage", () => {
132
+ renderHook(() => useTamboV1ThreadInput("custom_thread_id"));
133
+ expect(useTamboV1SendMessage).toHaveBeenCalledWith("custom_thread_id");
134
+ });
135
+ it("passes undefined threadId when not provided", () => {
136
+ renderHook(() => useTamboV1ThreadInput());
137
+ expect(useTamboV1SendMessage).toHaveBeenCalledWith(undefined);
138
+ });
139
+ });
140
+ describe("Mutation State", () => {
141
+ it("exposes isPending state", () => {
142
+ setupMock({ isPending: true });
143
+ const { result } = renderHook(() => useTamboV1ThreadInput());
144
+ expect(result.current.isPending).toBe(true);
145
+ });
146
+ it("exposes isError state", () => {
147
+ setupMock({ isError: true, error: new Error("Test error") });
148
+ const { result } = renderHook(() => useTamboV1ThreadInput());
149
+ expect(result.current.isError).toBe(true);
150
+ expect(result.current.error?.message).toBe("Test error");
151
+ });
152
+ it("exposes isSuccess state", () => {
153
+ setupMock({ isSuccess: true });
154
+ const { result } = renderHook(() => useTamboV1ThreadInput());
155
+ expect(result.current.isSuccess).toBe(true);
156
+ });
157
+ it("exposes reset function", () => {
158
+ const { result } = renderHook(() => useTamboV1ThreadInput());
159
+ act(() => {
160
+ result.current.reset();
161
+ });
162
+ expect(mockReset).toHaveBeenCalled();
163
+ });
164
+ });
165
+ });
166
+ //# sourceMappingURL=use-tambo-v1-thread-input.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-tambo-v1-thread-input.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-thread-input.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,wBAAwB;AACxB,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAClC,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE5B,oCAAoC;AACpC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,gDAAgD;AAChD,SAAS,SAAS,CAAC,YAAqC,EAAE;IACxD,MAAM,UAAU,GAAG;QACjB,WAAW,EAAE,eAAe;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MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;YACjC,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC;YAE7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;YAChC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC;YAE7D,GAAG,CAAC,GAAG,EAAE;gBACP,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,SAAS,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, act } from \"@testing-library/react\";\nimport { useTamboV1ThreadInput } from \"./use-tambo-v1-thread-input\";\n\n// Create mock functions\nconst mockMutateAsync = jest.fn();\nconst mockMutate = jest.fn();\nconst mockReset = jest.fn();\n\n// Mock useTamboV1SendMessage module\njest.mock(\"./use-tambo-v1-send-message\");\n\nimport { useTamboV1SendMessage } from \"./use-tambo-v1-send-message\";\n\n// Helper to set up the mock with default values\nfunction setupMock(overrides: Record<string, unknown> = {}) {\n const mockReturn = {\n mutateAsync: mockMutateAsync,\n mutate: mockMutate,\n isPending: false as const,\n isError: false as const,\n error: null,\n isSuccess: false as const,\n isIdle: true as const,\n isPaused: false as const,\n status: \"idle\" as const,\n data: undefined,\n variables: undefined,\n failureCount: 0,\n failureReason: null,\n reset: mockReset,\n context: undefined,\n submittedAt: 0,\n ...overrides,\n };\n jest.mocked(useTamboV1SendMessage).mockReturnValue(mockReturn);\n return mockReturn;\n}\n\ndescribe(\"useTamboV1ThreadInput\", () => {\n beforeEach(() => {\n jest.clearAllMocks();\n mockMutateAsync.mockResolvedValue({ threadId: \"thread_123\" });\n setupMock();\n });\n\n describe(\"State Management\", () => {\n it(\"initializes with empty value\", () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n expect(result.current.value).toBe(\"\");\n });\n\n it(\"updates value via setValue\", () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.setValue(\"Hello world\");\n });\n\n expect(result.current.value).toBe(\"Hello world\");\n });\n\n it(\"supports functional updates for setValue\", () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.setValue(\"Hello\");\n });\n\n act(() => {\n result.current.setValue((prev) => `${prev} world`);\n });\n\n expect(result.current.value).toBe(\"Hello world\");\n });\n });\n\n describe(\"Submit Behavior\", () => {\n it(\"submits message and clears input on success\", async () => {\n const { result } = renderHook(() => useTamboV1ThreadInput(\"thread_123\"));\n\n act(() => {\n result.current.setValue(\"Test message\");\n });\n\n await act(async () => {\n const response = await result.current.submit();\n expect(response.threadId).toBe(\"thread_123\");\n });\n\n // Input should be cleared\n expect(result.current.value).toBe(\"\");\n\n // Should have called mutateAsync with correct message format\n expect(mockMutateAsync).toHaveBeenCalledWith({\n message: {\n role: \"user\",\n content: [{ type: \"text\", text: \"Test message\" }],\n },\n debug: undefined,\n });\n });\n\n it(\"throws error when submitting empty message\", async () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n await expect(result.current.submit()).rejects.toThrow(\n \"Message cannot be empty\",\n );\n\n expect(mockMutateAsync).not.toHaveBeenCalled();\n });\n\n it(\"throws error when submitting whitespace-only message\", async () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.setValue(\" \");\n });\n\n await expect(result.current.submit()).rejects.toThrow(\n \"Message cannot be empty\",\n );\n\n expect(mockMutateAsync).not.toHaveBeenCalled();\n });\n\n it(\"passes debug option to mutation\", async () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.setValue(\"Debug message\");\n });\n\n await act(async () => {\n await result.current.submit({ debug: true });\n });\n\n expect(mockMutateAsync).toHaveBeenCalledWith({\n message: {\n role: \"user\",\n content: [{ type: \"text\", text: \"Debug message\" }],\n },\n debug: true,\n });\n });\n\n it(\"trims whitespace from message\", async () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.setValue(\" Trimmed message \");\n });\n\n await act(async () => {\n await result.current.submit();\n });\n\n expect(mockMutateAsync).toHaveBeenCalledWith({\n message: {\n role: \"user\",\n content: [{ type: \"text\", text: \"Trimmed message\" }],\n },\n debug: undefined,\n });\n });\n });\n\n describe(\"Thread ID Handling\", () => {\n it(\"passes threadId to useTamboV1SendMessage\", () => {\n renderHook(() => useTamboV1ThreadInput(\"custom_thread_id\"));\n\n expect(useTamboV1SendMessage).toHaveBeenCalledWith(\"custom_thread_id\");\n });\n\n it(\"passes undefined threadId when not provided\", () => {\n renderHook(() => useTamboV1ThreadInput());\n\n expect(useTamboV1SendMessage).toHaveBeenCalledWith(undefined);\n });\n });\n\n describe(\"Mutation State\", () => {\n it(\"exposes isPending state\", () => {\n setupMock({ isPending: true });\n\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n expect(result.current.isPending).toBe(true);\n });\n\n it(\"exposes isError state\", () => {\n setupMock({ isError: true, error: new Error(\"Test error\") });\n\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n expect(result.current.isError).toBe(true);\n expect(result.current.error?.message).toBe(\"Test error\");\n });\n\n it(\"exposes isSuccess state\", () => {\n setupMock({ isSuccess: true });\n\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n expect(result.current.isSuccess).toBe(true);\n });\n\n it(\"exposes reset function\", () => {\n const { result } = renderHook(() => useTamboV1ThreadInput());\n\n act(() => {\n result.current.reset();\n });\n\n expect(mockReset).toHaveBeenCalled();\n });\n });\n});\n"]}
package/esm/v1/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * import {
11
11
  * TamboV1Provider,
12
12
  * useTamboV1,
13
- * useTamboV1SendMessage,
13
+ * useTamboV1ThreadInput,
14
14
  * } from '@tambo-ai/react/v1';
15
15
  *
16
16
  * function App() {
@@ -28,21 +28,21 @@
28
28
  * function ChatInterface() {
29
29
  * const [threadId, setThreadId] = useState<string>();
30
30
  * const { messages, isStreaming } = useTamboV1(threadId);
31
- * const sendMessage = useTamboV1SendMessage(threadId);
31
+ * const { value, setValue, submit, isPending } = useTamboV1ThreadInput(threadId);
32
32
  *
33
- * const handleSend = async (text: string) => {
34
- * const result = await sendMessage.mutateAsync({
35
- * message: { role: 'user', content: [{ type: 'text', text }] },
36
- * });
33
+ * const handleSubmit = async (e: React.FormEvent) => {
34
+ * e.preventDefault();
35
+ * const result = await submit();
37
36
  * if (!threadId) setThreadId(result.threadId);
38
37
  * };
39
38
  *
40
39
  * return (
41
- * <div>
40
+ * <form onSubmit={handleSubmit}>
42
41
  * {messages.map(msg => <Message key={msg.id} message={msg} />)}
43
42
  * {isStreaming && <LoadingIndicator />}
44
- * <MessageInput onSend={handleSend} />
45
- * </div>
43
+ * <input value={value} onChange={(e) => setValue(e.target.value)} />
44
+ * <button disabled={isPending}>Send</button>
45
+ * </form>
46
46
  * );
47
47
  * }
48
48
  * ```
@@ -57,17 +57,28 @@
57
57
  * SDK types: `import type { ... } from '@tambo-ai/typescript-sdk'`
58
58
  * AG-UI events: `import { EventType, type BaseEvent } from '@ag-ui/core'`
59
59
  */
60
- export { TamboV1Provider, type TamboV1ProviderProps, } from "./providers/tambo-v1-provider";
60
+ export { TamboV1Provider, useContextKey, type TamboV1ProviderProps, } from "./providers/tambo-v1-provider";
61
61
  export { TamboV1StreamProvider, useStreamState, useStreamDispatch, useThreadManagement, type ThreadManagement, } from "./providers/tambo-v1-stream-context";
62
62
  export { TamboRegistryProvider } from "../providers/tambo-registry-provider";
63
+ export { TamboContextHelpersProvider, useTamboContextHelpers, } from "../providers/tambo-context-helpers-provider";
63
64
  export { useTamboV1, type UseTamboV1Return } from "./hooks/use-tambo-v1";
64
- export { useTamboV1Messages, type UseTamboV1MessagesReturn, } from "./hooks/use-tambo-v1-messages";
65
- export { useTamboV1SendMessage, type SendMessageOptions, } from "./hooks/use-tambo-v1-send-message";
65
+ export { useTamboV1ThreadInput, type UseTamboV1ThreadInputReturn, type SubmitOptions, } from "./hooks/use-tambo-v1-thread-input";
66
66
  export { useTamboV1Thread } from "./hooks/use-tambo-v1-thread";
67
67
  export { useTamboV1ThreadList } from "./hooks/use-tambo-v1-thread-list";
68
+ export { useTamboV1ComponentState, type UseTamboV1ComponentStateReturn, } from "./hooks/use-tambo-v1-component-state";
69
+ export { useTamboClient } from "../providers/tambo-client-provider";
70
+ export { useTamboRegistry } from "../providers/tambo-registry-provider";
71
+ export { useV1ComponentContent, useV1ComponentContentOptional, renderComponentContent, renderMessageContent, renderMessageComponents, isComponentContent, type V1ComponentContentContext, type RenderComponentOptions, } from "./utils/component-renderer";
68
72
  export { applyJsonPatch } from "./utils/json-patch";
69
73
  export { toAvailableComponent, toAvailableComponents, toAvailableTool, toAvailableTools, } from "./utils/registry-conversion";
70
74
  export { executeClientTool, executeAllPendingTools, type PendingToolCall, } from "./utils/tool-executor";
71
75
  export { ToolCallTracker } from "./utils/tool-call-tracker";
72
76
  export { handleEventStream } from "./utils/stream-handler";
77
+ export { defineTool } from "../util/registry";
78
+ export { currentPageContextHelper, currentTimeContextHelper, } from "../context-helpers";
79
+ export type { AdditionalContext, ContextHelperFn, ContextHelpers, } from "../context-helpers";
80
+ export type { ComponentContextToolMetadata, ComponentRegistry, ParameterSpec, RegisteredComponent, TamboTool, ToolAnnotations, } from "../model/component-metadata";
81
+ export { MCPTransport } from "../model/mcp-server-info";
82
+ export type { McpServerInfo, NormalizedMcpServerInfo, } from "../model/mcp-server-info";
83
+ export type { ListResourceItem, ReadResourceResult, ResourceSource, } from "../model/resource-info";
73
84
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAMH,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,GAC1B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,gBAAgB,GACtB,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAM7E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EACL,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,KAAK,kBAAkB,GACxB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eA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,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAO3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,4BAA4B,EAC5B,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,YAAY,EACV,aAAa,EACb,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,wBAAwB,CAAC"}
package/esm/v1/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * import {
11
11
  * TamboV1Provider,
12
12
  * useTamboV1,
13
- * useTamboV1SendMessage,
13
+ * useTamboV1ThreadInput,
14
14
  * } from '@tambo-ai/react/v1';
15
15
  *
16
16
  * function App() {
@@ -28,21 +28,21 @@
28
28
  * function ChatInterface() {
29
29
  * const [threadId, setThreadId] = useState<string>();
30
30
  * const { messages, isStreaming } = useTamboV1(threadId);
31
- * const sendMessage = useTamboV1SendMessage(threadId);
31
+ * const { value, setValue, submit, isPending } = useTamboV1ThreadInput(threadId);
32
32
  *
33
- * const handleSend = async (text: string) => {
34
- * const result = await sendMessage.mutateAsync({
35
- * message: { role: 'user', content: [{ type: 'text', text }] },
36
- * });
33
+ * const handleSubmit = async (e: React.FormEvent) => {
34
+ * e.preventDefault();
35
+ * const result = await submit();
37
36
  * if (!threadId) setThreadId(result.threadId);
38
37
  * };
39
38
  *
40
39
  * return (
41
- * <div>
40
+ * <form onSubmit={handleSubmit}>
42
41
  * {messages.map(msg => <Message key={msg.id} message={msg} />)}
43
42
  * {isStreaming && <LoadingIndicator />}
44
- * <MessageInput onSend={handleSend} />
45
- * </div>
43
+ * <input value={value} onChange={(e) => setValue(e.target.value)} />
44
+ * <button disabled={isPending}>Send</button>
45
+ * </form>
46
46
  * );
47
47
  * }
48
48
  * ```
@@ -60,18 +60,28 @@
60
60
  // =============================================================================
61
61
  // Providers
62
62
  // =============================================================================
63
- export { TamboV1Provider, } from "./providers/tambo-v1-provider";
63
+ export { TamboV1Provider, useContextKey, } from "./providers/tambo-v1-provider";
64
64
  export { TamboV1StreamProvider, useStreamState, useStreamDispatch, useThreadManagement, } from "./providers/tambo-v1-stream-context";
65
65
  // Re-export registry provider from beta SDK (works with v1)
66
66
  export { TamboRegistryProvider } from "../providers/tambo-registry-provider";
67
+ // Re-export context helpers from beta SDK (works with v1)
68
+ export { TamboContextHelpersProvider, useTamboContextHelpers, } from "../providers/tambo-context-helpers-provider";
67
69
  // =============================================================================
68
70
  // Hooks
69
71
  // =============================================================================
70
72
  export { useTamboV1 } from "./hooks/use-tambo-v1";
71
- export { useTamboV1Messages, } from "./hooks/use-tambo-v1-messages";
72
- export { useTamboV1SendMessage, } from "./hooks/use-tambo-v1-send-message";
73
+ export { useTamboV1ThreadInput, } from "./hooks/use-tambo-v1-thread-input";
73
74
  export { useTamboV1Thread } from "./hooks/use-tambo-v1-thread";
74
75
  export { useTamboV1ThreadList } from "./hooks/use-tambo-v1-thread-list";
76
+ export { useTamboV1ComponentState, } from "./hooks/use-tambo-v1-component-state";
77
+ // Re-export client hook from beta SDK (works with v1)
78
+ export { useTamboClient } from "../providers/tambo-client-provider";
79
+ // Re-export registry hook from beta SDK (works with v1)
80
+ export { useTamboRegistry } from "../providers/tambo-registry-provider";
81
+ // =============================================================================
82
+ // Component Rendering
83
+ // =============================================================================
84
+ export { useV1ComponentContent, useV1ComponentContentOptional, renderComponentContent, renderMessageContent, renderMessageComponents, isComponentContent, } from "./utils/component-renderer";
75
85
  // =============================================================================
76
86
  // Utilities
77
87
  // =============================================================================
@@ -80,4 +90,13 @@ export { toAvailableComponent, toAvailableComponents, toAvailableTool, toAvailab
80
90
  export { executeClientTool, executeAllPendingTools, } from "./utils/tool-executor";
81
91
  export { ToolCallTracker } from "./utils/tool-call-tracker";
82
92
  export { handleEventStream } from "./utils/stream-handler";
93
+ // =============================================================================
94
+ // Re-exports from Beta SDK (compatible with v1)
95
+ // =============================================================================
96
+ // Tool definition helper
97
+ export { defineTool } from "../util/registry";
98
+ // Built-in context helpers
99
+ export { currentPageContextHelper, currentTimeContextHelper, } from "../context-helpers";
100
+ // MCP server types
101
+ export { MCPTransport } from "../model/mcp-server-info";
83
102
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,OAAO,EACL,eAAe,GAEhB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,qCAAqC,CAAC;AAE7C,4DAA4D;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,gFAAgF;AAChF,QAAQ;AACR,gFAAgF;AAEhF,OAAO,EAAE,UAAU,EAAyB,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,GAEtB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `@tambo-ai/react/v1` - React SDK for Tambo v1 API\n *\n * Provides React hooks and providers for building AI-powered applications\n * using the v1 streaming API with AG-UI protocol.\n *\n * ## Quick Start\n *\n * ```tsx\n * import {\n * TamboV1Provider,\n * useTamboV1,\n * useTamboV1SendMessage,\n * } from '@tambo-ai/react/v1';\n *\n * function App() {\n * return (\n * <TamboV1Provider\n * apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}\n * components={[WeatherCard]}\n * tools={[searchTool]}\n * >\n * <ChatInterface />\n * </TamboV1Provider>\n * );\n * }\n *\n * function ChatInterface() {\n * const [threadId, setThreadId] = useState<string>();\n * const { messages, isStreaming } = useTamboV1(threadId);\n * const sendMessage = useTamboV1SendMessage(threadId);\n *\n * const handleSend = async (text: string) => {\n * const result = await sendMessage.mutateAsync({\n * message: { role: 'user', content: [{ type: 'text', text }] },\n * });\n * if (!threadId) setThreadId(result.threadId);\n * };\n *\n * return (\n * <div>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * <MessageInput onSend={handleSend} />\n * </div>\n * );\n * }\n * ```\n *\n * ## Type Imports\n *\n * Types are imported directly from specific files:\n * - Thread state: `import type { TamboV1Thread } from '@tambo-ai/react/v1/types/thread'`\n * - Messages: `import type { TamboV1Message } from '@tambo-ai/react/v1/types/message'`\n * - Custom events: `import type { ComponentStartEvent } from '@tambo-ai/react/v1/types/event'`\n *\n * SDK types: `import type { ... } from '@tambo-ai/typescript-sdk'`\n * AG-UI events: `import { EventType, type BaseEvent } from '@ag-ui/core'`\n */\n\n// =============================================================================\n// Providers\n// =============================================================================\n\nexport {\n TamboV1Provider,\n type TamboV1ProviderProps,\n} from \"./providers/tambo-v1-provider\";\n\nexport {\n TamboV1StreamProvider,\n useStreamState,\n useStreamDispatch,\n useThreadManagement,\n type ThreadManagement,\n} from \"./providers/tambo-v1-stream-context\";\n\n// Re-export registry provider from beta SDK (works with v1)\nexport { TamboRegistryProvider } from \"../providers/tambo-registry-provider\";\n\n// =============================================================================\n// Hooks\n// =============================================================================\n\nexport { useTamboV1, type UseTamboV1Return } from \"./hooks/use-tambo-v1\";\n\nexport {\n useTamboV1Messages,\n type UseTamboV1MessagesReturn,\n} from \"./hooks/use-tambo-v1-messages\";\n\nexport {\n useTamboV1SendMessage,\n type SendMessageOptions,\n} from \"./hooks/use-tambo-v1-send-message\";\n\nexport { useTamboV1Thread } from \"./hooks/use-tambo-v1-thread\";\n\nexport { useTamboV1ThreadList } from \"./hooks/use-tambo-v1-thread-list\";\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nexport { applyJsonPatch } from \"./utils/json-patch\";\n\nexport {\n toAvailableComponent,\n toAvailableComponents,\n toAvailableTool,\n toAvailableTools,\n} from \"./utils/registry-conversion\";\n\nexport {\n executeClientTool,\n executeAllPendingTools,\n type PendingToolCall,\n} from \"./utils/tool-executor\";\n\nexport { ToolCallTracker } from \"./utils/tool-call-tracker\";\n\nexport { handleEventStream } from \"./utils/stream-handler\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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EACjB,sBAAsB,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,gFAAgF;AAChF,gDAAgD;AAChD,gFAAgF;AAEhF,yBAAyB;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,2BAA2B;AAC3B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAmB5B,mBAAmB;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/**\n * `@tambo-ai/react/v1` - React SDK for Tambo v1 API\n *\n * Provides React hooks and providers for building AI-powered applications\n * using the v1 streaming API with AG-UI protocol.\n *\n * ## Quick Start\n *\n * ```tsx\n * import {\n * TamboV1Provider,\n * useTamboV1,\n * useTamboV1ThreadInput,\n * } from '@tambo-ai/react/v1';\n *\n * function App() {\n * return (\n * <TamboV1Provider\n * apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}\n * components={[WeatherCard]}\n * tools={[searchTool]}\n * >\n * <ChatInterface />\n * </TamboV1Provider>\n * );\n * }\n *\n * function ChatInterface() {\n * const [threadId, setThreadId] = useState<string>();\n * const { messages, isStreaming } = useTamboV1(threadId);\n * const { value, setValue, submit, isPending } = useTamboV1ThreadInput(threadId);\n *\n * const handleSubmit = async (e: React.FormEvent) => {\n * e.preventDefault();\n * const result = await submit();\n * if (!threadId) setThreadId(result.threadId);\n * };\n *\n * return (\n * <form onSubmit={handleSubmit}>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * <input value={value} onChange={(e) => setValue(e.target.value)} />\n * <button disabled={isPending}>Send</button>\n * </form>\n * );\n * }\n * ```\n *\n * ## Type Imports\n *\n * Types are imported directly from specific files:\n * - Thread state: `import type { TamboV1Thread } from '@tambo-ai/react/v1/types/thread'`\n * - Messages: `import type { TamboV1Message } from '@tambo-ai/react/v1/types/message'`\n * - Custom events: `import type { ComponentStartEvent } from '@tambo-ai/react/v1/types/event'`\n *\n * SDK types: `import type { ... } from '@tambo-ai/typescript-sdk'`\n * AG-UI events: `import { EventType, type BaseEvent } from '@ag-ui/core'`\n */\n\n// =============================================================================\n// Providers\n// =============================================================================\n\nexport {\n TamboV1Provider,\n useContextKey,\n type TamboV1ProviderProps,\n} from \"./providers/tambo-v1-provider\";\n\nexport {\n TamboV1StreamProvider,\n useStreamState,\n useStreamDispatch,\n useThreadManagement,\n type ThreadManagement,\n} from \"./providers/tambo-v1-stream-context\";\n\n// Re-export registry provider from beta SDK (works with v1)\nexport { TamboRegistryProvider } from \"../providers/tambo-registry-provider\";\n\n// Re-export context helpers from beta SDK (works with v1)\nexport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"../providers/tambo-context-helpers-provider\";\n\n// =============================================================================\n// Hooks\n// =============================================================================\n\nexport { useTamboV1, type UseTamboV1Return } from \"./hooks/use-tambo-v1\";\n\nexport {\n useTamboV1ThreadInput,\n type UseTamboV1ThreadInputReturn,\n type SubmitOptions,\n} from \"./hooks/use-tambo-v1-thread-input\";\n\nexport { useTamboV1Thread } from \"./hooks/use-tambo-v1-thread\";\n\nexport { useTamboV1ThreadList } from \"./hooks/use-tambo-v1-thread-list\";\n\nexport {\n useTamboV1ComponentState,\n type UseTamboV1ComponentStateReturn,\n} from \"./hooks/use-tambo-v1-component-state\";\n\n// Re-export client hook from beta SDK (works with v1)\nexport { useTamboClient } from \"../providers/tambo-client-provider\";\n\n// Re-export registry hook from beta SDK (works with v1)\nexport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\n\n// =============================================================================\n// Component Rendering\n// =============================================================================\n\nexport {\n useV1ComponentContent,\n useV1ComponentContentOptional,\n renderComponentContent,\n renderMessageContent,\n renderMessageComponents,\n isComponentContent,\n type V1ComponentContentContext,\n type RenderComponentOptions,\n} from \"./utils/component-renderer\";\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nexport { applyJsonPatch } from \"./utils/json-patch\";\n\nexport {\n toAvailableComponent,\n toAvailableComponents,\n toAvailableTool,\n toAvailableTools,\n} from \"./utils/registry-conversion\";\n\nexport {\n executeClientTool,\n executeAllPendingTools,\n type PendingToolCall,\n} from \"./utils/tool-executor\";\n\nexport { ToolCallTracker } from \"./utils/tool-call-tracker\";\n\nexport { handleEventStream } from \"./utils/stream-handler\";\n\n// =============================================================================\n// Re-exports from Beta SDK (compatible with v1)\n// =============================================================================\n\n// Tool definition helper\nexport { defineTool } from \"../util/registry\";\n\n// Built-in context helpers\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"../context-helpers\";\n\n// Context helper types\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"../context-helpers\";\n\n// Component and tool types\nexport type {\n ComponentContextToolMetadata,\n ComponentRegistry,\n ParameterSpec,\n RegisteredComponent,\n TamboTool,\n ToolAnnotations,\n} from \"../model/component-metadata\";\n\n// MCP server types\nexport { MCPTransport } from \"../model/mcp-server-info\";\nexport type {\n McpServerInfo,\n NormalizedMcpServerInfo,\n} from \"../model/mcp-server-info\";\n\n// Resource types\nexport type {\n ListResourceItem,\n ReadResourceResult,\n ResourceSource,\n} from \"../model/resource-info\";\n"]}
@@ -4,6 +4,7 @@
4
4
  * Composes the necessary providers for the v1 SDK:
5
5
  * - TamboClientProvider: API client and authentication
6
6
  * - TamboRegistryProvider: Component and tool registration
7
+ * - TamboContextHelpersProvider: Context helper functions
7
8
  * - TamboV1StreamProvider: Streaming state management
8
9
  *
9
10
  * This provider should wrap your entire application or the portion
@@ -13,7 +14,14 @@ import React, { type PropsWithChildren } from "react";
13
14
  import { QueryClient } from "@tanstack/react-query";
14
15
  import { type TamboClientProviderProps } from "../../providers/tambo-client-provider";
15
16
  import { type TamboRegistryProviderProps } from "../../providers/tambo-registry-provider";
17
+ import type { ContextHelpers } from "../../context-helpers";
16
18
  import type { McpServerInfo } from "../../model/mcp-server-info";
19
+ import type { ListResourceItem, ResourceSource } from "../../model/resource-info";
20
+ /**
21
+ * Hook to access the contextKey from TamboV1Provider.
22
+ * @returns The contextKey if provided, undefined otherwise
23
+ */
24
+ export declare function useContextKey(): string | undefined;
17
25
  /**
18
26
  * Props for TamboV1Provider
19
27
  */
@@ -38,6 +46,35 @@ export interface TamboV1ProviderProps extends Pick<TamboClientProviderProps, "ap
38
46
  * If not provided, an error will be thrown for unknown tools.
39
47
  */
40
48
  onCallUnregisteredTool?: TamboRegistryProviderProps["onCallUnregisteredTool"];
49
+ /**
50
+ * Static resources to register with the registry.
51
+ * These will be available for the AI to access.
52
+ */
53
+ resources?: ListResourceItem[];
54
+ /**
55
+ * Dynamic resource search function.
56
+ * Must be paired with getResource.
57
+ * Called when searching for resources dynamically.
58
+ */
59
+ listResources?: ResourceSource["listResources"];
60
+ /**
61
+ * Dynamic resource fetch function.
62
+ * Must be paired with listResources.
63
+ * Called when fetching a specific resource by URI.
64
+ */
65
+ getResource?: ResourceSource["getResource"];
66
+ /**
67
+ * Configuration for context helpers.
68
+ * A dictionary of functions that provide additional context to the AI.
69
+ * Each key becomes the context name, and the function returns the value.
70
+ */
71
+ contextHelpers?: ContextHelpers;
72
+ /**
73
+ * Optional context key for thread scoping/isolation.
74
+ * Threads created with the same contextKey are grouped together.
75
+ * Useful for multi-tenant applications or separating conversation contexts.
76
+ */
77
+ contextKey?: string;
41
78
  /**
42
79
  * Optional custom QueryClient instance.
43
80
  * If not provided, a default client will be created.
@@ -67,6 +104,11 @@ export interface TamboV1ProviderProps extends Pick<TamboClientProviderProps, "ap
67
104
  * @param props.tools - Tools to register for client-side execution
68
105
  * @param props.mcpServers - MCP servers to register for additional tools/resources
69
106
  * @param props.onCallUnregisteredTool - Callback for handling unknown tool calls
107
+ * @param props.resources - Static resources to register with the AI
108
+ * @param props.listResources - Dynamic resource search function (must be paired with getResource)
109
+ * @param props.getResource - Dynamic resource fetch function (must be paired with listResources)
110
+ * @param props.contextHelpers - Configuration for context helper functions
111
+ * @param props.contextKey - Optional context key for thread scoping/isolation
70
112
  * @param props.queryClient - Optional custom React Query client
71
113
  * @param props.children - Child components
72
114
  * @returns Provider component tree
@@ -87,5 +129,5 @@ export interface TamboV1ProviderProps extends Pick<TamboClientProviderProps, "ap
87
129
  * }
88
130
  * ```
89
131
  */
90
- export declare function TamboV1Provider({ apiKey, tamboUrl, environment, userToken, components, tools, mcpServers, onCallUnregisteredTool, queryClient, children, }: PropsWithChildren<TamboV1ProviderProps>): React.JSX.Element;
132
+ export declare function TamboV1Provider({ apiKey, tamboUrl, environment, userToken, components, tools, mcpServers, onCallUnregisteredTool, resources, listResources, getResource, contextHelpers, contextKey, queryClient, children, }: PropsWithChildren<TamboV1ProviderProps>): React.JSX.Element;
91
133
  //# sourceMappingURL=tambo-v1-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-v1-provider.d.ts","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-provider.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAChD,wBAAwB,EACxB,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,WAAW,CACpD;IACC;;;OAGG;IACH,UAAU,CAAC,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;IAEtD;;;OAGG;IACH,KAAK,CAAC,EAAE,0BAA0B,CAAC,OAAO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,GAAG,aAAa,GAAG,WAAW,CACpD;IACC;;;OAGG;IACH,UAAU,CAAC,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;IAEtD;;;OAGG;IACH,KAAK,CAAC,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE5C;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IAExC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,0BAA0B,CAAC,wBAAwB,CAAC,CAAC;IAE9E;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAE/B;;;;OAIG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAEhD;;;;OAIG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;IAE5C;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,sBAAsB,EACtB,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,UAAU,EACV,WAAW,EACX,QAAQ,GACT,EAAE,iBAAiB,CAAC,oBAAoB,CAAC,qBA2CzC"}
@@ -5,16 +5,29 @@
5
5
  * Composes the necessary providers for the v1 SDK:
6
6
  * - TamboClientProvider: API client and authentication
7
7
  * - TamboRegistryProvider: Component and tool registration
8
+ * - TamboContextHelpersProvider: Context helper functions
8
9
  * - TamboV1StreamProvider: Streaming state management
9
10
  *
10
11
  * This provider should wrap your entire application or the portion
11
12
  * that needs access to Tambo v1 functionality.
12
13
  */
13
- import React, { useState } from "react";
14
+ import React, { createContext, useContext, useState, } from "react";
14
15
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
15
16
  import { TamboClientProvider, } from "../../providers/tambo-client-provider";
16
17
  import { TamboRegistryProvider, } from "../../providers/tambo-registry-provider";
18
+ import { TamboContextHelpersProvider } from "../../providers/tambo-context-helpers-provider";
17
19
  import { TamboV1StreamProvider } from "./tambo-v1-stream-context";
20
+ /**
21
+ * Context for providing contextKey to child components.
22
+ */
23
+ const ContextKeyContext = createContext(undefined);
24
+ /**
25
+ * Hook to access the contextKey from TamboV1Provider.
26
+ * @returns The contextKey if provided, undefined otherwise
27
+ */
28
+ export function useContextKey() {
29
+ return useContext(ContextKeyContext);
30
+ }
18
31
  /**
19
32
  * Main provider for the Tambo v1 SDK.
20
33
  *
@@ -34,6 +47,11 @@ import { TamboV1StreamProvider } from "./tambo-v1-stream-context";
34
47
  * @param props.tools - Tools to register for client-side execution
35
48
  * @param props.mcpServers - MCP servers to register for additional tools/resources
36
49
  * @param props.onCallUnregisteredTool - Callback for handling unknown tool calls
50
+ * @param props.resources - Static resources to register with the AI
51
+ * @param props.listResources - Dynamic resource search function (must be paired with getResource)
52
+ * @param props.getResource - Dynamic resource fetch function (must be paired with listResources)
53
+ * @param props.contextHelpers - Configuration for context helper functions
54
+ * @param props.contextKey - Optional context key for thread scoping/isolation
37
55
  * @param props.queryClient - Optional custom React Query client
38
56
  * @param props.children - Child components
39
57
  * @returns Provider component tree
@@ -54,7 +72,7 @@ import { TamboV1StreamProvider } from "./tambo-v1-stream-context";
54
72
  * }
55
73
  * ```
56
74
  */
57
- export function TamboV1Provider({ apiKey, tamboUrl, environment, userToken, components, tools, mcpServers, onCallUnregisteredTool, queryClient, children, }) {
75
+ export function TamboV1Provider({ apiKey, tamboUrl, environment, userToken, components, tools, mcpServers, onCallUnregisteredTool, resources, listResources, getResource, contextHelpers, contextKey, queryClient, children, }) {
58
76
  // Create a stable default QueryClient if none provided.
59
77
  // Using useState to avoid SSR issues with module-level singletons.
60
78
  const [defaultQueryClient] = useState(() => new QueryClient({
@@ -68,7 +86,9 @@ export function TamboV1Provider({ apiKey, tamboUrl, environment, userToken, comp
68
86
  const client = queryClient ?? defaultQueryClient;
69
87
  return (React.createElement(QueryClientProvider, { client: client },
70
88
  React.createElement(TamboClientProvider, { apiKey: apiKey, tamboUrl: tamboUrl, environment: environment, userToken: userToken },
71
- React.createElement(TamboRegistryProvider, { components: components, tools: tools, mcpServers: mcpServers, onCallUnregisteredTool: onCallUnregisteredTool },
72
- React.createElement(TamboV1StreamProvider, null, children)))));
89
+ React.createElement(TamboRegistryProvider, { components: components, tools: tools, mcpServers: mcpServers, onCallUnregisteredTool: onCallUnregisteredTool, resources: resources, listResources: listResources, getResource: getResource },
90
+ React.createElement(TamboContextHelpersProvider, { contextHelpers: contextHelpers },
91
+ React.createElement(ContextKeyContext.Provider, { value: contextKey },
92
+ React.createElement(TamboV1StreamProvider, null, children)))))));
73
93
  }
74
94
  //# sourceMappingURL=tambo-v1-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-v1-provider.js","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,EAA0B,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EACL,mBAAmB,GAEpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,qBAAqB,GAEtB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AA6ClE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,QAAQ,GACgC;IACxC,wDAAwD;IACxD,mEAAmE;IACnE,MAAM,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CACnC,GAAG,EAAE,CACH,IAAI,WAAW,CAAC;QACd,cAAc,EAAE;YACd,OAAO,EAAE;gBACP,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE,CAAC;aACT;SACF;KACF,CAAC,CACL,CAAC;IAEF,MAAM,MAAM,GAAG,WAAW,IAAI,kBAAkB,CAAC;IAEjD,OAAO,CACL,oBAAC,mBAAmB,IAAC,MAAM,EAAE,MAAM;QACjC,oBAAC,mBAAmB,IAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;YAEpB,oBAAC,qBAAqB,IACpB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB;gBAE9C,oBAAC,qBAAqB,QAAE,QAAQ,CAAyB,CACnC,CACJ,CACF,CACvB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * TamboV1Provider - Main Provider for v1 API\n *\n * Composes the necessary providers for the v1 SDK:\n * - TamboClientProvider: API client and authentication\n * - TamboRegistryProvider: Component and tool registration\n * - TamboV1StreamProvider: Streaming state management\n *\n * This provider should wrap your entire application or the portion\n * that needs access to Tambo v1 functionality.\n */\n\nimport React, { type PropsWithChildren, useState } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport {\n TamboClientProvider,\n type TamboClientProviderProps,\n} from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryProvider,\n type TamboRegistryProviderProps,\n} from \"../../providers/tambo-registry-provider\";\nimport type { McpServerInfo } from \"../../model/mcp-server-info\";\nimport { TamboV1StreamProvider } from \"./tambo-v1-stream-context\";\n\n/**\n * Props for TamboV1Provider\n */\nexport interface TamboV1ProviderProps extends Pick<\n TamboClientProviderProps,\n \"apiKey\" | \"tamboUrl\" | \"environment\" | \"userToken\"\n> {\n /**\n * Components to register with the registry.\n * These will be available for the AI to use in responses.\n */\n components?: TamboRegistryProviderProps[\"components\"];\n\n /**\n * Tools to register with the registry.\n * These will be executed client-side when requested by the AI.\n */\n tools?: TamboRegistryProviderProps[\"tools\"];\n\n /**\n * MCP servers to register with the registry.\n * These provide additional tools and resources from MCP-compatible servers.\n */\n mcpServers?: (McpServerInfo | string)[];\n\n /**\n * Callback function called when an unregistered tool is called.\n * If not provided, an error will be thrown for unknown tools.\n */\n onCallUnregisteredTool?: TamboRegistryProviderProps[\"onCallUnregisteredTool\"];\n\n /**\n * Optional custom QueryClient instance.\n * If not provided, a default client will be created.\n */\n queryClient?: QueryClient;\n\n /**\n * Children components\n */\n children: React.ReactNode;\n}\n\n/**\n * Main provider for the Tambo v1 SDK.\n *\n * Composes TamboClientProvider, TamboRegistryProvider, and TamboV1StreamProvider\n * to provide a complete context for building AI-powered applications.\n *\n * Threads are managed dynamically through useTamboV1() hook functions:\n * - startNewThread() - Begin a new conversation\n * - switchThread(threadId) - Switch to an existing thread\n * - initThread(threadId) - Initialize a thread for receiving events\n * @param props - Provider configuration\n * @param props.apiKey - Tambo API key for authentication\n * @param props.tamboUrl - Optional custom Tambo API URL\n * @param props.environment - Optional environment configuration\n * @param props.userToken - Optional OAuth token for user authentication\n * @param props.components - Components to register with the AI\n * @param props.tools - Tools to register for client-side execution\n * @param props.mcpServers - MCP servers to register for additional tools/resources\n * @param props.onCallUnregisteredTool - Callback for handling unknown tool calls\n * @param props.queryClient - Optional custom React Query client\n * @param props.children - Child components\n * @returns Provider component tree\n * @example\n * ```tsx\n * import { TamboV1Provider } from '@tambo-ai/react/v1';\n *\n * function App() {\n * return (\n * <TamboV1Provider\n * apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}\n * components={[WeatherCard, StockChart]}\n * tools={[searchTool, calculatorTool]}\n * >\n * <ChatInterface />\n * </TamboV1Provider>\n * );\n * }\n * ```\n */\nexport function TamboV1Provider({\n apiKey,\n tamboUrl,\n environment,\n userToken,\n components,\n tools,\n mcpServers,\n onCallUnregisteredTool,\n queryClient,\n children,\n}: PropsWithChildren<TamboV1ProviderProps>) {\n // Create a stable default QueryClient if none provided.\n // Using useState to avoid SSR issues with module-level singletons.\n const [defaultQueryClient] = useState(\n () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 1000,\n retry: 1,\n },\n },\n }),\n );\n\n const client = queryClient ?? defaultQueryClient;\n\n return (\n <QueryClientProvider client={client}>\n <TamboClientProvider\n apiKey={apiKey}\n tamboUrl={tamboUrl}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboV1StreamProvider>{children}</TamboV1StreamProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n </QueryClientProvider>\n );\n}\n"]}
1
+ {"version":3,"file":"tambo-v1-provider.js","sourceRoot":"","sources":["../../../src/v1/providers/tambo-v1-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,UAAU,EAEV,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EACL,mBAAmB,GAEpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,qBAAqB,GAEtB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAO7F,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE;;GAEG;AACH,MAAM,i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R,CACJ,CACF,CACvB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * TamboV1Provider - Main Provider for v1 API\n *\n * Composes the necessary providers for the v1 SDK:\n * - TamboClientProvider: API client and authentication\n * - TamboRegistryProvider: Component and tool registration\n * - TamboContextHelpersProvider: Context helper functions\n * - TamboV1StreamProvider: Streaming state management\n *\n * This provider should wrap your entire application or the portion\n * that needs access to Tambo v1 functionality.\n */\n\nimport React, {\n createContext,\n useContext,\n type PropsWithChildren,\n useState,\n} from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport {\n TamboClientProvider,\n type TamboClientProviderProps,\n} from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryProvider,\n type TamboRegistryProviderProps,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboContextHelpersProvider } from \"../../providers/tambo-context-helpers-provider\";\nimport type { ContextHelpers } from \"../../context-helpers\";\nimport type { McpServerInfo } from \"../../model/mcp-server-info\";\nimport type {\n ListResourceItem,\n ResourceSource,\n} from \"../../model/resource-info\";\nimport { TamboV1StreamProvider } from \"./tambo-v1-stream-context\";\n\n/**\n * Context for providing contextKey to child components.\n */\nconst ContextKeyContext = createContext<string | undefined>(undefined);\n\n/**\n * Hook to access the contextKey from TamboV1Provider.\n * @returns The contextKey if provided, undefined otherwise\n */\nexport function useContextKey(): string | undefined {\n return useContext(ContextKeyContext);\n}\n\n/**\n * Props for TamboV1Provider\n */\nexport interface TamboV1ProviderProps extends Pick<\n TamboClientProviderProps,\n \"apiKey\" | \"tamboUrl\" | \"environment\" | \"userToken\"\n> {\n /**\n * Components to register with the registry.\n * These will be available for the AI to use in responses.\n */\n components?: TamboRegistryProviderProps[\"components\"];\n\n /**\n * Tools to register with the registry.\n * These will be executed client-side when requested by the AI.\n */\n tools?: TamboRegistryProviderProps[\"tools\"];\n\n /**\n * MCP servers to register with the registry.\n * These provide additional tools and resources from MCP-compatible servers.\n */\n mcpServers?: (McpServerInfo | string)[];\n\n /**\n * Callback function called when an unregistered tool is called.\n * If not provided, an error will be thrown for unknown tools.\n */\n onCallUnregisteredTool?: TamboRegistryProviderProps[\"onCallUnregisteredTool\"];\n\n /**\n * Static resources to register with the registry.\n * These will be available for the AI to access.\n */\n resources?: ListResourceItem[];\n\n /**\n * Dynamic resource search function.\n * Must be paired with getResource.\n * Called when searching for resources dynamically.\n */\n listResources?: ResourceSource[\"listResources\"];\n\n /**\n * Dynamic resource fetch function.\n * Must be paired with listResources.\n * Called when fetching a specific resource by URI.\n */\n getResource?: ResourceSource[\"getResource\"];\n\n /**\n * Configuration for context helpers.\n * A dictionary of functions that provide additional context to the AI.\n * Each key becomes the context name, and the function returns the value.\n */\n contextHelpers?: ContextHelpers;\n\n /**\n * Optional context key for thread scoping/isolation.\n * Threads created with the same contextKey are grouped together.\n * Useful for multi-tenant applications or separating conversation contexts.\n */\n contextKey?: string;\n\n /**\n * Optional custom QueryClient instance.\n * If not provided, a default client will be created.\n */\n queryClient?: QueryClient;\n\n /**\n * Children components\n */\n children: React.ReactNode;\n}\n\n/**\n * Main provider for the Tambo v1 SDK.\n *\n * Composes TamboClientProvider, TamboRegistryProvider, and TamboV1StreamProvider\n * to provide a complete context for building AI-powered applications.\n *\n * Threads are managed dynamically through useTamboV1() hook functions:\n * - startNewThread() - Begin a new conversation\n * - switchThread(threadId) - Switch to an existing thread\n * - initThread(threadId) - Initialize a thread for receiving events\n * @param props - Provider configuration\n * @param props.apiKey - Tambo API key for authentication\n * @param props.tamboUrl - Optional custom Tambo API URL\n * @param props.environment - Optional environment configuration\n * @param props.userToken - Optional OAuth token for user authentication\n * @param props.components - Components to register with the AI\n * @param props.tools - Tools to register for client-side execution\n * @param props.mcpServers - MCP servers to register for additional tools/resources\n * @param props.onCallUnregisteredTool - Callback for handling unknown tool calls\n * @param props.resources - Static resources to register with the AI\n * @param props.listResources - Dynamic resource search function (must be paired with getResource)\n * @param props.getResource - Dynamic resource fetch function (must be paired with listResources)\n * @param props.contextHelpers - Configuration for context helper functions\n * @param props.contextKey - Optional context key for thread scoping/isolation\n * @param props.queryClient - Optional custom React Query client\n * @param props.children - Child components\n * @returns Provider component tree\n * @example\n * ```tsx\n * import { TamboV1Provider } from '@tambo-ai/react/v1';\n *\n * function App() {\n * return (\n * <TamboV1Provider\n * apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}\n * components={[WeatherCard, StockChart]}\n * tools={[searchTool, calculatorTool]}\n * >\n * <ChatInterface />\n * </TamboV1Provider>\n * );\n * }\n * ```\n */\nexport function TamboV1Provider({\n apiKey,\n tamboUrl,\n environment,\n userToken,\n components,\n tools,\n mcpServers,\n onCallUnregisteredTool,\n resources,\n listResources,\n getResource,\n contextHelpers,\n contextKey,\n queryClient,\n children,\n}: PropsWithChildren<TamboV1ProviderProps>) {\n // Create a stable default QueryClient if none provided.\n // Using useState to avoid SSR issues with module-level singletons.\n const [defaultQueryClient] = useState(\n () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 1000,\n retry: 1,\n },\n },\n }),\n );\n\n const client = queryClient ?? defaultQueryClient;\n\n return (\n <QueryClientProvider client={client}>\n <TamboClientProvider\n apiKey={apiKey}\n tamboUrl={tamboUrl}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n resources={resources}\n listResources={listResources}\n getResource={getResource}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <ContextKeyContext.Provider value={contextKey}>\n <TamboV1StreamProvider>{children}</TamboV1StreamProvider>\n </ContextKeyContext.Provider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n </QueryClientProvider>\n );\n}\n"]}