@tambo-ai/react 0.72.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +22 -9
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +9 -2
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +152 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +511 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +6 -57
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.js +7 -67
- package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +201 -72
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +16 -7
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/index.d.ts +22 -13
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +31 -39
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +27 -9
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.js +22 -11
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.test.js +27 -10
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +19 -10
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.js +43 -53
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.test.js +94 -19
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js +212 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.js +162 -0
- package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.js +191 -0
- package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
- package/dist/v1/utils/component-renderer.d.ts +15 -67
- package/dist/v1/utils/component-renderer.d.ts.map +1 -1
- package/dist/v1/utils/component-renderer.js +3 -149
- package/dist/v1/utils/component-renderer.js.map +1 -1
- package/dist/v1/utils/component-renderer.test.js +15 -350
- package/dist/v1/utils/component-renderer.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +22 -9
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +9 -2
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +22 -9
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +91 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +149 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +506 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +6 -57
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.js +5 -66
- package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +199 -73
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +6 -4
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +2 -2
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +2 -2
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +16 -7
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/index.d.ts +22 -13
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +23 -18
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +27 -9
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.js +20 -10
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.test.js +28 -11
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +19 -10
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js +44 -54
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.test.js +95 -20
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts +74 -0
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.js +176 -0
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.js +157 -0
- package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +105 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.js +153 -0
- package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -0
- package/esm/v1/utils/component-renderer.d.ts +15 -67
- package/esm/v1/utils/component-renderer.d.ts.map +1 -1
- package/esm/v1/utils/component-renderer.js +4 -146
- package/esm/v1/utils/component-renderer.js.map +1 -1
- package/esm/v1/utils/component-renderer.test.js +16 -351
- package/esm/v1/utils/component-renderer.test.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,367 +1,27 @@
|
|
|
1
|
-
// React import needed for JSX transform (jsxImportSource is not set to react-jsx)
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
1
|
import React from "react";
|
|
4
2
|
import { render, screen } from "@testing-library/react";
|
|
5
|
-
import {
|
|
6
|
-
// Test component that displays its props
|
|
7
|
-
function TestComponent({ title, count }) {
|
|
8
|
-
return (React.createElement("div", { "data-testid": "test-component" },
|
|
9
|
-
React.createElement("span", { "data-testid": "title" }, title),
|
|
10
|
-
React.createElement("span", { "data-testid": "count" }, count)));
|
|
11
|
-
}
|
|
12
|
-
// Test loading component
|
|
13
|
-
function TestLoadingComponent() {
|
|
14
|
-
return React.createElement("div", { "data-testid": "loading" }, "Loading...");
|
|
15
|
-
}
|
|
3
|
+
import { useV1ComponentContent, V1ComponentContentProvider, } from "./component-renderer";
|
|
16
4
|
// Test component that uses the content context
|
|
17
|
-
|
|
5
|
+
const ContextAwareComponent = () => {
|
|
18
6
|
const context = useV1ComponentContent();
|
|
19
7
|
return (React.createElement("div", { "data-testid": "context-aware" },
|
|
20
8
|
React.createElement("span", { "data-testid": "componentId" }, context.componentId),
|
|
21
9
|
React.createElement("span", { "data-testid": "threadId" }, context.threadId),
|
|
22
|
-
React.createElement("span", { "data-testid": "messageId" }, context.messageId)
|
|
23
|
-
}
|
|
24
|
-
const mockRegistry = {
|
|
25
|
-
TestComponent: {
|
|
26
|
-
component: TestComponent,
|
|
27
|
-
name: "TestComponent",
|
|
28
|
-
description: "A test component",
|
|
29
|
-
props: {},
|
|
30
|
-
contextTools: [],
|
|
31
|
-
},
|
|
32
|
-
TestWithLoading: {
|
|
33
|
-
component: TestComponent,
|
|
34
|
-
loadingComponent: TestLoadingComponent,
|
|
35
|
-
name: "TestWithLoading",
|
|
36
|
-
description: "A test component with loading state",
|
|
37
|
-
props: {},
|
|
38
|
-
contextTools: [],
|
|
39
|
-
},
|
|
40
|
-
ContextAware: {
|
|
41
|
-
component: ContextAwareComponent,
|
|
42
|
-
name: "ContextAware",
|
|
43
|
-
description: "A context-aware component",
|
|
44
|
-
props: {},
|
|
45
|
-
contextTools: [],
|
|
46
|
-
},
|
|
10
|
+
React.createElement("span", { "data-testid": "messageId" }, context.messageId),
|
|
11
|
+
React.createElement("span", { "data-testid": "componentName" }, context.componentName)));
|
|
47
12
|
};
|
|
48
|
-
describe("
|
|
49
|
-
it("
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
id: "comp_1",
|
|
53
|
-
name: "Test",
|
|
54
|
-
props: {},
|
|
55
|
-
streamingState: "done",
|
|
56
|
-
};
|
|
57
|
-
expect(isComponentContent(content)).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
it("returns false for text content", () => {
|
|
60
|
-
const content = { type: "text", text: "hello" };
|
|
61
|
-
expect(isComponentContent(content)).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe("renderComponentContent", () => {
|
|
65
|
-
it("renders a component from registry", () => {
|
|
66
|
-
const content = {
|
|
67
|
-
type: "component",
|
|
68
|
-
id: "comp_1",
|
|
69
|
-
name: "TestComponent",
|
|
70
|
-
props: { title: "Hello", count: 42 },
|
|
71
|
-
streamingState: "done",
|
|
72
|
-
};
|
|
73
|
-
const result = renderComponentContent(content, {
|
|
74
|
-
threadId: "thread_1",
|
|
75
|
-
messageId: "msg_1",
|
|
76
|
-
componentList: mockRegistry,
|
|
77
|
-
});
|
|
78
|
-
expect(result.renderedComponent).not.toBeNull();
|
|
79
|
-
// Render and check output
|
|
80
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
81
|
-
expect(screen.getByTestId("title")).toHaveTextContent("Hello");
|
|
82
|
-
expect(screen.getByTestId("count")).toHaveTextContent("42");
|
|
83
|
-
});
|
|
84
|
-
it("returns null renderedComponent for unknown component", () => {
|
|
85
|
-
const content = {
|
|
86
|
-
type: "component",
|
|
87
|
-
id: "comp_1",
|
|
88
|
-
name: "UnknownComponent",
|
|
89
|
-
props: {},
|
|
90
|
-
streamingState: "done",
|
|
91
|
-
};
|
|
92
|
-
const consoleWarn = jest.spyOn(console, "warn").mockImplementation();
|
|
93
|
-
const result = renderComponentContent(content, {
|
|
94
|
-
threadId: "thread_1",
|
|
95
|
-
messageId: "msg_1",
|
|
96
|
-
componentList: mockRegistry,
|
|
97
|
-
});
|
|
98
|
-
expect(result.renderedComponent).toBeNull();
|
|
99
|
-
expect(consoleWarn).toHaveBeenCalledWith('Component "UnknownComponent" not found in registry');
|
|
100
|
-
consoleWarn.mockRestore();
|
|
101
|
-
});
|
|
102
|
-
it("shows loading component when streaming", () => {
|
|
103
|
-
const content = {
|
|
104
|
-
type: "component",
|
|
105
|
-
id: "comp_1",
|
|
106
|
-
name: "TestWithLoading",
|
|
107
|
-
props: { title: "Loading Test", count: 0 },
|
|
108
|
-
streamingState: "streaming",
|
|
109
|
-
};
|
|
110
|
-
const result = renderComponentContent(content, {
|
|
111
|
-
threadId: "thread_1",
|
|
112
|
-
messageId: "msg_1",
|
|
113
|
-
componentList: mockRegistry,
|
|
114
|
-
});
|
|
115
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
116
|
-
expect(screen.getByTestId("loading")).toHaveTextContent("Loading...");
|
|
117
|
-
});
|
|
118
|
-
it("shows main component when done streaming", () => {
|
|
119
|
-
const content = {
|
|
120
|
-
type: "component",
|
|
121
|
-
id: "comp_1",
|
|
122
|
-
name: "TestWithLoading",
|
|
123
|
-
props: { title: "Done Test", count: 99 },
|
|
124
|
-
streamingState: "done",
|
|
125
|
-
};
|
|
126
|
-
const result = renderComponentContent(content, {
|
|
127
|
-
threadId: "thread_1",
|
|
128
|
-
messageId: "msg_1",
|
|
129
|
-
componentList: mockRegistry,
|
|
130
|
-
});
|
|
131
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
132
|
-
expect(screen.getByTestId("title")).toHaveTextContent("Done Test");
|
|
133
|
-
expect(screen.getByTestId("count")).toHaveTextContent("99");
|
|
134
|
-
});
|
|
135
|
-
it("provides component context to rendered components", () => {
|
|
136
|
-
const content = {
|
|
137
|
-
type: "component",
|
|
138
|
-
id: "comp_123",
|
|
139
|
-
name: "ContextAware",
|
|
140
|
-
props: {},
|
|
141
|
-
streamingState: "done",
|
|
142
|
-
};
|
|
143
|
-
const result = renderComponentContent(content, {
|
|
144
|
-
threadId: "thread_456",
|
|
145
|
-
messageId: "msg_789",
|
|
146
|
-
componentList: mockRegistry,
|
|
147
|
-
});
|
|
148
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
13
|
+
describe("V1ComponentContentProvider", () => {
|
|
14
|
+
it("provides context to child components", () => {
|
|
15
|
+
render(React.createElement(V1ComponentContentProvider, { componentId: "comp_123", threadId: "thread_456", messageId: "msg_789", componentName: "TestComponent" },
|
|
16
|
+
React.createElement(ContextAwareComponent, null)));
|
|
149
17
|
expect(screen.getByTestId("componentId")).toHaveTextContent("comp_123");
|
|
150
18
|
expect(screen.getByTestId("threadId")).toHaveTextContent("thread_456");
|
|
151
19
|
expect(screen.getByTestId("messageId")).toHaveTextContent("msg_789");
|
|
20
|
+
expect(screen.getByTestId("componentName")).toHaveTextContent("TestComponent");
|
|
152
21
|
});
|
|
153
22
|
});
|
|
154
|
-
describe("
|
|
155
|
-
it("
|
|
156
|
-
const content = [
|
|
157
|
-
{ type: "text", text: "Hello" },
|
|
158
|
-
{
|
|
159
|
-
type: "component",
|
|
160
|
-
id: "comp_1",
|
|
161
|
-
name: "TestComponent",
|
|
162
|
-
props: { title: "Test", count: 1 },
|
|
163
|
-
streamingState: "done",
|
|
164
|
-
},
|
|
165
|
-
{ type: "text", text: "World" },
|
|
166
|
-
];
|
|
167
|
-
const result = renderMessageContent(content, {
|
|
168
|
-
threadId: "thread_1",
|
|
169
|
-
messageId: "msg_1",
|
|
170
|
-
componentList: mockRegistry,
|
|
171
|
-
});
|
|
172
|
-
expect(result).toHaveLength(3);
|
|
173
|
-
expect(result[0]).toEqual({ type: "text", text: "Hello" });
|
|
174
|
-
expect(result[1].renderedComponent).not.toBeNull();
|
|
175
|
-
expect(result[2]).toEqual({ type: "text", text: "World" });
|
|
176
|
-
});
|
|
177
|
-
it("handles multiple component blocks in a message", () => {
|
|
178
|
-
const content = [
|
|
179
|
-
{
|
|
180
|
-
type: "component",
|
|
181
|
-
id: "comp_1",
|
|
182
|
-
name: "TestComponent",
|
|
183
|
-
props: { title: "First", count: 1 },
|
|
184
|
-
streamingState: "done",
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
type: "component",
|
|
188
|
-
id: "comp_2",
|
|
189
|
-
name: "TestComponent",
|
|
190
|
-
props: { title: "Second", count: 2 },
|
|
191
|
-
streamingState: "done",
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
const result = renderMessageContent(content, {
|
|
195
|
-
threadId: "thread_1",
|
|
196
|
-
messageId: "msg_1",
|
|
197
|
-
componentList: mockRegistry,
|
|
198
|
-
});
|
|
199
|
-
expect(result).toHaveLength(2);
|
|
200
|
-
expect(result[0].renderedComponent).not.toBeNull();
|
|
201
|
-
expect(result[1].renderedComponent).not.toBeNull();
|
|
202
|
-
});
|
|
203
|
-
it("handles tool_use content blocks unchanged", () => {
|
|
204
|
-
const content = [
|
|
205
|
-
{
|
|
206
|
-
type: "tool_use",
|
|
207
|
-
id: "tool_1",
|
|
208
|
-
name: "search",
|
|
209
|
-
input: { query: "test" },
|
|
210
|
-
},
|
|
211
|
-
];
|
|
212
|
-
const result = renderMessageContent(content, {
|
|
213
|
-
threadId: "thread_1",
|
|
214
|
-
messageId: "msg_1",
|
|
215
|
-
componentList: mockRegistry,
|
|
216
|
-
});
|
|
217
|
-
expect(result).toHaveLength(1);
|
|
218
|
-
expect(result[0]).toEqual(content[0]);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
describe("renderComponentContent edge cases", () => {
|
|
222
|
-
it("shows main component when streamingState is 'started' (no loading component)", () => {
|
|
223
|
-
const content = {
|
|
224
|
-
type: "component",
|
|
225
|
-
id: "comp_1",
|
|
226
|
-
name: "TestComponent",
|
|
227
|
-
props: { title: "Started", count: 0 },
|
|
228
|
-
streamingState: "started",
|
|
229
|
-
};
|
|
230
|
-
const result = renderComponentContent(content, {
|
|
231
|
-
threadId: "thread_1",
|
|
232
|
-
messageId: "msg_1",
|
|
233
|
-
componentList: mockRegistry,
|
|
234
|
-
});
|
|
235
|
-
// TestComponent has no loading component, so it shows main even when streaming
|
|
236
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
237
|
-
expect(screen.getByTestId("title")).toHaveTextContent("Started");
|
|
238
|
-
});
|
|
239
|
-
it("shows loading component when streamingState is 'started' and loading exists", () => {
|
|
240
|
-
const content = {
|
|
241
|
-
type: "component",
|
|
242
|
-
id: "comp_1",
|
|
243
|
-
name: "TestWithLoading",
|
|
244
|
-
props: { title: "Started", count: 0 },
|
|
245
|
-
streamingState: "started",
|
|
246
|
-
};
|
|
247
|
-
const result = renderComponentContent(content, {
|
|
248
|
-
threadId: "thread_1",
|
|
249
|
-
messageId: "msg_1",
|
|
250
|
-
componentList: mockRegistry,
|
|
251
|
-
});
|
|
252
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
253
|
-
expect(screen.getByTestId("loading")).toHaveTextContent("Loading...");
|
|
254
|
-
});
|
|
255
|
-
it("passes state as initialState prop", () => {
|
|
256
|
-
// Component that reads initialState
|
|
257
|
-
function StatefulComponent({ initialState, }) {
|
|
258
|
-
return (React.createElement("div", { "data-testid": "initial-count" }, initialState?.count ?? "none"));
|
|
259
|
-
}
|
|
260
|
-
const registryWithStateful = {
|
|
261
|
-
StatefulComponent: {
|
|
262
|
-
component: StatefulComponent,
|
|
263
|
-
name: "StatefulComponent",
|
|
264
|
-
description: "A stateful component",
|
|
265
|
-
props: {},
|
|
266
|
-
contextTools: [],
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
const content = {
|
|
270
|
-
type: "component",
|
|
271
|
-
id: "comp_1",
|
|
272
|
-
name: "StatefulComponent",
|
|
273
|
-
props: {},
|
|
274
|
-
state: { count: 42 },
|
|
275
|
-
streamingState: "done",
|
|
276
|
-
};
|
|
277
|
-
const result = renderComponentContent(content, {
|
|
278
|
-
threadId: "thread_1",
|
|
279
|
-
messageId: "msg_1",
|
|
280
|
-
componentList: registryWithStateful,
|
|
281
|
-
});
|
|
282
|
-
render(React.createElement(React.Fragment, null, result.renderedComponent));
|
|
283
|
-
expect(screen.getByTestId("initial-count")).toHaveTextContent("42");
|
|
284
|
-
});
|
|
285
|
-
it("preserves original content properties in returned object", () => {
|
|
286
|
-
const content = {
|
|
287
|
-
type: "component",
|
|
288
|
-
id: "comp_custom",
|
|
289
|
-
name: "TestComponent",
|
|
290
|
-
props: { title: "Test", count: 5 },
|
|
291
|
-
state: { value: "preserved" },
|
|
292
|
-
streamingState: "done",
|
|
293
|
-
};
|
|
294
|
-
const result = renderComponentContent(content, {
|
|
295
|
-
threadId: "thread_1",
|
|
296
|
-
messageId: "msg_1",
|
|
297
|
-
componentList: mockRegistry,
|
|
298
|
-
});
|
|
299
|
-
expect(result.id).toBe("comp_custom");
|
|
300
|
-
expect(result.name).toBe("TestComponent");
|
|
301
|
-
expect(result.props).toEqual({ title: "Test", count: 5 });
|
|
302
|
-
expect(result.state).toEqual({ value: "preserved" });
|
|
303
|
-
expect(result.streamingState).toBe("done");
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
describe("useV1ComponentContentOptional", () => {
|
|
307
|
-
it("returns null when used outside rendered component", () => {
|
|
308
|
-
function TestConsumer() {
|
|
309
|
-
const context = useV1ComponentContentOptional();
|
|
310
|
-
return (React.createElement("div", { "data-testid": "context" }, context ? "has context" : "no context"));
|
|
311
|
-
}
|
|
312
|
-
render(React.createElement(TestConsumer, null));
|
|
313
|
-
expect(screen.getByTestId("context")).toHaveTextContent("no context");
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
describe("renderMessageComponents", () => {
|
|
317
|
-
it("renders all components in a message", () => {
|
|
318
|
-
const message = {
|
|
319
|
-
id: "msg_1",
|
|
320
|
-
role: "assistant",
|
|
321
|
-
content: [
|
|
322
|
-
{ type: "text", text: "Here is the weather:" },
|
|
323
|
-
{
|
|
324
|
-
type: "component",
|
|
325
|
-
id: "comp_1",
|
|
326
|
-
name: "TestComponent",
|
|
327
|
-
props: { title: "Weather", count: 72 },
|
|
328
|
-
streamingState: "done",
|
|
329
|
-
},
|
|
330
|
-
],
|
|
331
|
-
createdAt: "2024-01-01T00:00:00.000Z",
|
|
332
|
-
};
|
|
333
|
-
const result = renderMessageComponents(message, {
|
|
334
|
-
threadId: "thread_1",
|
|
335
|
-
componentList: mockRegistry,
|
|
336
|
-
});
|
|
337
|
-
expect(result.id).toBe("msg_1");
|
|
338
|
-
expect(result.content).toHaveLength(2);
|
|
339
|
-
expect(result.content[0]).toEqual({
|
|
340
|
-
type: "text",
|
|
341
|
-
text: "Here is the weather:",
|
|
342
|
-
});
|
|
343
|
-
expect(result.content[1].renderedComponent).not.toBeNull();
|
|
344
|
-
});
|
|
345
|
-
it("preserves message metadata", () => {
|
|
346
|
-
const message = {
|
|
347
|
-
id: "msg_123",
|
|
348
|
-
role: "assistant",
|
|
349
|
-
content: [],
|
|
350
|
-
createdAt: "2024-01-01T00:00:00.000Z",
|
|
351
|
-
metadata: { custom: "value" },
|
|
352
|
-
};
|
|
353
|
-
const result = renderMessageComponents(message, {
|
|
354
|
-
threadId: "thread_1",
|
|
355
|
-
componentList: mockRegistry,
|
|
356
|
-
});
|
|
357
|
-
expect(result.id).toBe("msg_123");
|
|
358
|
-
expect(result.role).toBe("assistant");
|
|
359
|
-
expect(result.createdAt).toBe("2024-01-01T00:00:00.000Z");
|
|
360
|
-
expect(result.metadata).toEqual({ custom: "value" });
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
describe("useV1ComponentContent error handling", () => {
|
|
364
|
-
it("throws when used outside rendered component", () => {
|
|
23
|
+
describe("useV1ComponentContent", () => {
|
|
24
|
+
it("throws when used outside provider", () => {
|
|
365
25
|
function TestConsumer() {
|
|
366
26
|
useV1ComponentContent();
|
|
367
27
|
return React.createElement("div", null, "Should not render");
|
|
@@ -371,5 +31,10 @@ describe("useV1ComponentContent error handling", () => {
|
|
|
371
31
|
expect(() => render(React.createElement(TestConsumer, null))).toThrow("useV1ComponentContent must be used within a rendered component");
|
|
372
32
|
consoleSpy.mockRestore();
|
|
373
33
|
});
|
|
34
|
+
it("returns context when used within provider", () => {
|
|
35
|
+
render(React.createElement(V1ComponentContentProvider, { componentId: "comp_test", threadId: "thread_test", messageId: "msg_test", componentName: "TestComp" },
|
|
36
|
+
React.createElement(ContextAwareComponent, null)));
|
|
37
|
+
expect(screen.getByTestId("componentId")).toHaveTextContent("comp_test");
|
|
38
|
+
});
|
|
374
39
|
});
|
|
375
40
|
//# sourceMappingURL=component-renderer.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-renderer.test.js","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.test.tsx"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,6DAA6D;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,oBAAo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C5C,gEAAgE,CACjE,CAAC;QAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// React import needed for JSX transform (jsxImportSource is not set to react-jsx)\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport React from \"react\";\nimport { render, screen } from \"@testing-library/react\";\nimport type { ComponentRegistry } from \"../../model/component-metadata\";\nimport type { V1ComponentContent } from \"../types/message\";\nimport {\n isComponentContent,\n renderComponentContent,\n renderMessageContent,\n renderMessageComponents,\n useV1ComponentContent,\n useV1ComponentContentOptional,\n} from \"./component-renderer\";\n\n// Test component that displays its props\nfunction TestComponent({ title, count }: { title: string; count: number }) {\n return (\n <div data-testid=\"test-component\">\n <span data-testid=\"title\">{title}</span>\n <span data-testid=\"count\">{count}</span>\n </div>\n );\n}\n\n// Test loading component\nfunction TestLoadingComponent() {\n return <div data-testid=\"loading\">Loading...</div>;\n}\n\n// Test component that uses the content context\nfunction ContextAwareComponent() {\n const context = useV1ComponentContent();\n return (\n <div data-testid=\"context-aware\">\n <span data-testid=\"componentId\">{context.componentId}</span>\n <span data-testid=\"threadId\">{context.threadId}</span>\n <span data-testid=\"messageId\">{context.messageId}</span>\n </div>\n );\n}\n\nconst mockRegistry: ComponentRegistry = {\n TestComponent: {\n component: TestComponent,\n name: \"TestComponent\",\n description: \"A test component\",\n props: {},\n contextTools: [],\n },\n TestWithLoading: {\n component: TestComponent,\n loadingComponent: TestLoadingComponent,\n name: \"TestWithLoading\",\n description: \"A test component with loading state\",\n props: {},\n contextTools: [],\n },\n ContextAware: {\n component: ContextAwareComponent,\n name: \"ContextAware\",\n description: \"A context-aware component\",\n props: {},\n contextTools: [],\n },\n};\n\ndescribe(\"isComponentContent\", () => {\n it(\"returns true for component content\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"Test\",\n props: {},\n streamingState: \"done\",\n };\n expect(isComponentContent(content)).toBe(true);\n });\n\n it(\"returns false for text content\", () => {\n const content = { type: \"text\", text: \"hello\" };\n expect(isComponentContent(content as any)).toBe(false);\n });\n});\n\ndescribe(\"renderComponentContent\", () => {\n it(\"renders a component from registry\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: { title: \"Hello\", count: 42 },\n streamingState: \"done\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result.renderedComponent).not.toBeNull();\n\n // Render and check output\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"title\")).toHaveTextContent(\"Hello\");\n expect(screen.getByTestId(\"count\")).toHaveTextContent(\"42\");\n });\n\n it(\"returns null renderedComponent for unknown component\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"UnknownComponent\",\n props: {},\n streamingState: \"done\",\n };\n\n const consoleWarn = jest.spyOn(console, \"warn\").mockImplementation();\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result.renderedComponent).toBeNull();\n expect(consoleWarn).toHaveBeenCalledWith(\n 'Component \"UnknownComponent\" not found in registry',\n );\n\n consoleWarn.mockRestore();\n });\n\n it(\"shows loading component when streaming\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestWithLoading\",\n props: { title: \"Loading Test\", count: 0 },\n streamingState: \"streaming\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"loading\")).toHaveTextContent(\"Loading...\");\n });\n\n it(\"shows main component when done streaming\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestWithLoading\",\n props: { title: \"Done Test\", count: 99 },\n streamingState: \"done\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"title\")).toHaveTextContent(\"Done Test\");\n expect(screen.getByTestId(\"count\")).toHaveTextContent(\"99\");\n });\n\n it(\"provides component context to rendered components\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_123\",\n name: \"ContextAware\",\n props: {},\n streamingState: \"done\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_456\",\n messageId: \"msg_789\",\n componentList: mockRegistry,\n });\n\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"componentId\")).toHaveTextContent(\"comp_123\");\n expect(screen.getByTestId(\"threadId\")).toHaveTextContent(\"thread_456\");\n expect(screen.getByTestId(\"messageId\")).toHaveTextContent(\"msg_789\");\n });\n});\n\ndescribe(\"renderMessageContent\", () => {\n it(\"renders component content blocks and passes through others\", () => {\n const content = [\n { type: \"text\", text: \"Hello\" },\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: { title: \"Test\", count: 1 },\n streamingState: \"done\",\n } as V1ComponentContent,\n { type: \"text\", text: \"World\" },\n ];\n\n const result = renderMessageContent(content as any, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result).toHaveLength(3);\n expect(result[0]).toEqual({ type: \"text\", text: \"Hello\" });\n expect((result[1] as any).renderedComponent).not.toBeNull();\n expect(result[2]).toEqual({ type: \"text\", text: \"World\" });\n });\n\n it(\"handles multiple component blocks in a message\", () => {\n const content = [\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: { title: \"First\", count: 1 },\n streamingState: \"done\",\n } as V1ComponentContent,\n {\n type: \"component\",\n id: \"comp_2\",\n name: \"TestComponent\",\n props: { title: \"Second\", count: 2 },\n streamingState: \"done\",\n } as V1ComponentContent,\n ];\n\n const result = renderMessageContent(content as any, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result).toHaveLength(2);\n expect((result[0] as V1ComponentContent).renderedComponent).not.toBeNull();\n expect((result[1] as V1ComponentContent).renderedComponent).not.toBeNull();\n });\n\n it(\"handles tool_use content blocks unchanged\", () => {\n const content = [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"search\",\n input: { query: \"test\" },\n },\n ];\n\n const result = renderMessageContent(content as any, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result).toHaveLength(1);\n expect(result[0]).toEqual(content[0]);\n });\n});\n\ndescribe(\"renderComponentContent edge cases\", () => {\n it(\"shows main component when streamingState is 'started' (no loading component)\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: { title: \"Started\", count: 0 },\n streamingState: \"started\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n // TestComponent has no loading component, so it shows main even when streaming\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"title\")).toHaveTextContent(\"Started\");\n });\n\n it(\"shows loading component when streamingState is 'started' and loading exists\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestWithLoading\",\n props: { title: \"Started\", count: 0 },\n streamingState: \"started\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"loading\")).toHaveTextContent(\"Loading...\");\n });\n\n it(\"passes state as initialState prop\", () => {\n // Component that reads initialState\n function StatefulComponent({\n initialState,\n }: {\n initialState?: { count: number };\n }) {\n return (\n <div data-testid=\"initial-count\">{initialState?.count ?? \"none\"}</div>\n );\n }\n\n const registryWithStateful: ComponentRegistry = {\n StatefulComponent: {\n component: StatefulComponent,\n name: \"StatefulComponent\",\n description: \"A stateful component\",\n props: {},\n contextTools: [],\n },\n };\n\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_1\",\n name: \"StatefulComponent\",\n props: {},\n state: { count: 42 },\n streamingState: \"done\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: registryWithStateful,\n });\n\n render(<>{result.renderedComponent}</>);\n expect(screen.getByTestId(\"initial-count\")).toHaveTextContent(\"42\");\n });\n\n it(\"preserves original content properties in returned object\", () => {\n const content: V1ComponentContent = {\n type: \"component\",\n id: \"comp_custom\",\n name: \"TestComponent\",\n props: { title: \"Test\", count: 5 },\n state: { value: \"preserved\" },\n streamingState: \"done\",\n };\n\n const result = renderComponentContent(content, {\n threadId: \"thread_1\",\n messageId: \"msg_1\",\n componentList: mockRegistry,\n });\n\n expect(result.id).toBe(\"comp_custom\");\n expect(result.name).toBe(\"TestComponent\");\n expect(result.props).toEqual({ title: \"Test\", count: 5 });\n expect(result.state).toEqual({ value: \"preserved\" });\n expect(result.streamingState).toBe(\"done\");\n });\n});\n\ndescribe(\"useV1ComponentContentOptional\", () => {\n it(\"returns null when used outside rendered component\", () => {\n function TestConsumer() {\n const context = useV1ComponentContentOptional();\n return (\n <div data-testid=\"context\">\n {context ? \"has context\" : \"no context\"}\n </div>\n );\n }\n\n render(<TestConsumer />);\n expect(screen.getByTestId(\"context\")).toHaveTextContent(\"no context\");\n });\n});\n\ndescribe(\"renderMessageComponents\", () => {\n it(\"renders all components in a message\", () => {\n const message = {\n id: \"msg_1\",\n role: \"assistant\" as const,\n content: [\n { type: \"text\" as const, text: \"Here is the weather:\" },\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: { title: \"Weather\", count: 72 },\n streamingState: \"done\",\n } as V1ComponentContent,\n ],\n createdAt: \"2024-01-01T00:00:00.000Z\",\n };\n\n const result = renderMessageComponents(message, {\n threadId: \"thread_1\",\n componentList: mockRegistry,\n });\n\n expect(result.id).toBe(\"msg_1\");\n expect(result.content).toHaveLength(2);\n expect(result.content[0]).toEqual({\n type: \"text\",\n text: \"Here is the weather:\",\n });\n expect(\n (result.content[1] as V1ComponentContent).renderedComponent,\n ).not.toBeNull();\n });\n\n it(\"preserves message metadata\", () => {\n const message = {\n id: \"msg_123\",\n role: \"assistant\" as const,\n content: [],\n createdAt: \"2024-01-01T00:00:00.000Z\",\n metadata: { custom: \"value\" },\n };\n\n const result = renderMessageComponents(message, {\n threadId: \"thread_1\",\n componentList: mockRegistry,\n });\n\n expect(result.id).toBe(\"msg_123\");\n expect(result.role).toBe(\"assistant\");\n expect(result.createdAt).toBe(\"2024-01-01T00:00:00.000Z\");\n expect(result.metadata).toEqual({ custom: \"value\" });\n });\n});\n\ndescribe(\"useV1ComponentContent error handling\", () => {\n it(\"throws when used outside rendered component\", () => {\n function TestConsumer() {\n useV1ComponentContent();\n return <div>Should not render</div>;\n }\n\n // Suppress React error boundary logs\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n expect(() => render(<TestConsumer />)).toThrow(\n \"useV1ComponentContent must be used within a rendered component\",\n );\n\n consoleSpy.mockRestore();\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"component-renderer.test.js","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAE9B,+CAA+C;AAC/C,MAAM,qBAAqB,GAAa,GAAG,EAAE;IAC3C,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;IACxC,OAAO,CACL,4CAAiB,eAAe;QAC9B,6CAAkB,aAAa,IAAE,OAAO,CAAC,WAAW,CAAQ;QAC5D,6CAAkB,UAAU,IAAE,OAAO,CAAC,QAAQ,CAAQ;QACtD,6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EAAgE,CACjE,CAAC;QAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CACJ,oBAAC,0BAA0B,IACzB,WAAW,EAAC,WAAW,EACvB,QAAQ,EAAC,aAAa,EACtB,SAAS,EAAC,UAAU,EACpB,aAAa,EAAC,UAAU;YAExB,oBAAC,qBAAqB,OAAG,CACE,CAC9B,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport { render, screen } from \"@testing-library/react\";\nimport {\n useV1ComponentContent,\n V1ComponentContentProvider,\n} from \"./component-renderer\";\n\n// Test component that uses the content context\nconst ContextAwareComponent: React.FC = () => {\n const context = useV1ComponentContent();\n return (\n <div data-testid=\"context-aware\">\n <span data-testid=\"componentId\">{context.componentId}</span>\n <span data-testid=\"threadId\">{context.threadId}</span>\n <span data-testid=\"messageId\">{context.messageId}</span>\n <span data-testid=\"componentName\">{context.componentName}</span>\n </div>\n );\n};\n\ndescribe(\"V1ComponentContentProvider\", () => {\n it(\"provides context to child components\", () => {\n render(\n <V1ComponentContentProvider\n componentId=\"comp_123\"\n threadId=\"thread_456\"\n messageId=\"msg_789\"\n componentName=\"TestComponent\"\n >\n <ContextAwareComponent />\n </V1ComponentContentProvider>,\n );\n\n expect(screen.getByTestId(\"componentId\")).toHaveTextContent(\"comp_123\");\n expect(screen.getByTestId(\"threadId\")).toHaveTextContent(\"thread_456\");\n expect(screen.getByTestId(\"messageId\")).toHaveTextContent(\"msg_789\");\n expect(screen.getByTestId(\"componentName\")).toHaveTextContent(\n \"TestComponent\",\n );\n });\n});\n\ndescribe(\"useV1ComponentContent\", () => {\n it(\"throws when used outside provider\", () => {\n function TestConsumer() {\n useV1ComponentContent();\n return <div>Should not render</div>;\n }\n\n // Suppress React error boundary logs\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n expect(() => render(<TestConsumer />)).toThrow(\n \"useV1ComponentContent must be used within a rendered component\",\n );\n\n consoleSpy.mockRestore();\n });\n\n it(\"returns context when used within provider\", () => {\n render(\n <V1ComponentContentProvider\n componentId=\"comp_test\"\n threadId=\"thread_test\"\n messageId=\"msg_test\"\n componentName=\"TestComp\"\n >\n <ContextAwareComponent />\n </V1ComponentContentProvider>,\n );\n\n expect(screen.getByTestId(\"componentId\")).toHaveTextContent(\"comp_test\");\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tambo-ai/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.73.0",
|
|
4
4
|
"description": "React client package for Tambo AI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
86
86
|
"@standard-community/standard-json": "^0.3.5",
|
|
87
87
|
"@standard-schema/spec": "^1.1.0",
|
|
88
|
-
"@tambo-ai/typescript-sdk": "^0.
|
|
88
|
+
"@tambo-ai/typescript-sdk": "^0.87.0",
|
|
89
89
|
"@tanstack/react-query": "^5.90.16",
|
|
90
90
|
"fast-equals": "^5.3.3",
|
|
91
91
|
"fast-json-patch": "^3.1.1",
|