@copilotkit/react-native 1.67.1 → 1.68.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/chunk-C0xms8kb.cjs +34 -0
- package/dist/components/index.cjs +146 -33
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.mjs +144 -32
- package/dist/components/index.mjs.map +1 -1
- package/dist/headless.cjs +40 -4
- package/dist/headless.d.cts +3 -3
- package/dist/headless.d.mts +3 -3
- package/dist/headless.mjs +5 -4
- package/dist/index.cjs +43 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +1 -1
- package/dist/polyfills/streams.cjs +1 -1
- package/dist/useRenderTool-BBxnOOeJ.d.mts +161 -0
- package/dist/useRenderTool-BWo11PCL.d.cts +161 -0
- package/dist/{useRenderTool-DLavcsVB.cjs → useRenderTool-CKEPq7MQ.cjs} +20 -34
- package/dist/useRenderTool-CKEPq7MQ.cjs.map +1 -0
- package/dist/{useRenderTool-DUqpS97B.mjs → useRenderTool-l7M-I8rT.mjs} +18 -33
- package/dist/useRenderTool-l7M-I8rT.mjs.map +1 -0
- package/package.json +9 -6
- package/scripts/__tests__/fixtures/stray-react-dom-headless.js +16 -0
- package/scripts/__tests__/fixtures/tiny-headless.js +10 -0
- package/scripts/__tests__/fixtures/warning-headless.js +13 -0
- package/scripts/__tests__/measure-headless.test.mjs +275 -0
- package/scripts/measure-headless.mjs +310 -0
- package/src/CopilotKitProvider.tsx +1 -2
- package/src/__mocks__/test-copilotkit.tsx +116 -0
- package/src/__mocks__/tool-fixtures.ts +50 -0
- package/src/__tests__/headless-entry-surface.test.ts +464 -46
- package/src/__tests__/headless-integration.test.tsx +12 -1
- package/src/__tests__/headless-value-exports.test.ts +369 -0
- package/src/components/CopilotChat.tsx +218 -32
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -126
- package/src/components/__tests__/CopilotChat.test.tsx +5 -49
- package/src/components/__tests__/CopilotChatToolCalls.test.tsx +468 -0
- package/src/headless.ts +36 -14
- package/src/hooks/__tests__/render-tool-call.integration.test.tsx +181 -0
- package/src/hooks/__tests__/useRenderTool.test.tsx +232 -267
- package/src/hooks/index.ts +1 -7
- package/src/hooks/render-tool-types.ts +55 -0
- package/src/hooks/useRenderTool.ts +29 -57
- package/src/index.ts +13 -5
- package/dist/RenderToolContext-CBNKcJqz.cjs +0 -126
- package/dist/RenderToolContext-CBNKcJqz.cjs.map +0 -1
- package/dist/RenderToolContext-D8M-JhD1.mjs +0 -75
- package/dist/RenderToolContext-D8M-JhD1.mjs.map +0 -1
- package/dist/useRenderTool-9YDIfZ0D.d.mts +0 -164
- package/dist/useRenderTool-BugVTDoM.d.cts +0 -164
- package/dist/useRenderTool-DLavcsVB.cjs.map +0 -1
- package/dist/useRenderTool-DUqpS97B.mjs.map +0 -1
- package/src/hooks/RenderToolContext.tsx +0 -150
- package/src/hooks/__tests__/RenderToolContext.test.tsx +0 -264
|
@@ -12,15 +12,19 @@ const hoisted = vi.hoisted(() => {
|
|
|
12
12
|
addMessage: vi.fn(),
|
|
13
13
|
},
|
|
14
14
|
mockRunAgent: vi.fn().mockResolvedValue(undefined),
|
|
15
|
-
mockToolRegistry: vi.fn(() => new Map()),
|
|
16
15
|
mockExecutingToolCallIds: new Set<string>(),
|
|
17
16
|
};
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
// ─── Mocks ────────────────────────────────────────────────────────────────────
|
|
21
20
|
|
|
21
|
+
// react-core is mocked wholesale for these unit-level edge cases. Tool-call
|
|
22
|
+
// rendering against a REAL useRenderToolCall lives in
|
|
23
|
+
// CopilotChatToolCalls.test.tsx; here useRenderToolCall resolves no renderer so
|
|
24
|
+
// tool calls fall through to the "Called: <name>" placeholder.
|
|
22
25
|
vi.mock("@copilotkit/react-core/v2/headless", () => ({
|
|
23
26
|
useAgent: vi.fn(() => ({ agent: hoisted.mockAgent })),
|
|
27
|
+
useRenderToolCall: vi.fn(() => () => null),
|
|
24
28
|
}));
|
|
25
29
|
|
|
26
30
|
vi.mock("@copilotkit/react-core/v2/context", () => ({
|
|
@@ -52,10 +56,6 @@ vi.mock("../messages/UserMessage", () => ({
|
|
|
52
56
|
},
|
|
53
57
|
}));
|
|
54
58
|
|
|
55
|
-
vi.mock("../../hooks/RenderToolContext", () => ({
|
|
56
|
-
useRenderToolRegistry: () => hoisted.mockToolRegistry(),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
59
|
// Mock react-native components with testable DOM elements
|
|
60
60
|
vi.mock("react-native", () => {
|
|
61
61
|
const React = require("react");
|
|
@@ -138,7 +138,6 @@ describe("CopilotChat edge cases", () => {
|
|
|
138
138
|
hoisted.mockAgent.isRunning = false;
|
|
139
139
|
hoisted.mockAgent.addMessage = vi.fn();
|
|
140
140
|
hoisted.mockRunAgent.mockResolvedValue(undefined);
|
|
141
|
-
hoisted.mockToolRegistry.mockReturnValue(new Map());
|
|
142
141
|
hoisted.mockExecutingToolCallIds.clear();
|
|
143
142
|
});
|
|
144
143
|
|
|
@@ -179,126 +178,6 @@ describe("CopilotChat edge cases", () => {
|
|
|
179
178
|
});
|
|
180
179
|
});
|
|
181
180
|
|
|
182
|
-
describe("malformed tool call arguments", () => {
|
|
183
|
-
it("handles invalid JSON in tool arguments gracefully", () => {
|
|
184
|
-
const mockRenderer = (props: any) => {
|
|
185
|
-
return React.createElement(
|
|
186
|
-
"div",
|
|
187
|
-
{ "data-testid": "tool-render" },
|
|
188
|
-
`args: ${JSON.stringify(props.args)}`,
|
|
189
|
-
);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const toolMap = new Map([["brokenTool", mockRenderer]]);
|
|
193
|
-
hoisted.mockToolRegistry.mockReturnValue(toolMap);
|
|
194
|
-
|
|
195
|
-
hoisted.mockAgent.messages = [
|
|
196
|
-
{
|
|
197
|
-
id: "1",
|
|
198
|
-
role: "assistant",
|
|
199
|
-
content: "",
|
|
200
|
-
toolCalls: [
|
|
201
|
-
{
|
|
202
|
-
id: "tc-1",
|
|
203
|
-
type: "function" as const,
|
|
204
|
-
function: {
|
|
205
|
-
name: "brokenTool",
|
|
206
|
-
arguments: "this is not valid JSON{{{",
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
];
|
|
212
|
-
|
|
213
|
-
// Suppress the expected console.warn
|
|
214
|
-
const spy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
215
|
-
|
|
216
|
-
const { getByTestId } = render(<CopilotChat />);
|
|
217
|
-
|
|
218
|
-
// Should render with empty args instead of crashing
|
|
219
|
-
expect(getByTestId("tool-render")).toBeTruthy();
|
|
220
|
-
expect(getByTestId("tool-render").textContent).toBe("args: {}");
|
|
221
|
-
|
|
222
|
-
spy.mockRestore();
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("handles empty string arguments in tool calls", () => {
|
|
226
|
-
const mockRenderer = (props: any) => {
|
|
227
|
-
return React.createElement(
|
|
228
|
-
"div",
|
|
229
|
-
{ "data-testid": "tool-render" },
|
|
230
|
-
`args: ${JSON.stringify(props.args)}`,
|
|
231
|
-
);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
const toolMap = new Map([["emptyArgsTool", mockRenderer]]);
|
|
235
|
-
hoisted.mockToolRegistry.mockReturnValue(toolMap);
|
|
236
|
-
|
|
237
|
-
hoisted.mockAgent.messages = [
|
|
238
|
-
{
|
|
239
|
-
id: "1",
|
|
240
|
-
role: "assistant",
|
|
241
|
-
content: "",
|
|
242
|
-
toolCalls: [
|
|
243
|
-
{
|
|
244
|
-
id: "tc-1",
|
|
245
|
-
type: "function" as const,
|
|
246
|
-
function: {
|
|
247
|
-
name: "emptyArgsTool",
|
|
248
|
-
arguments: "",
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
];
|
|
254
|
-
|
|
255
|
-
const { getByTestId } = render(<CopilotChat />);
|
|
256
|
-
|
|
257
|
-
expect(getByTestId("tool-render")).toBeTruthy();
|
|
258
|
-
expect(getByTestId("tool-render").textContent).toBe("args: {}");
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe("tool call status", () => {
|
|
263
|
-
it("passes 'executing' status when tool call is in executingToolCallIds", () => {
|
|
264
|
-
const receivedProps: any[] = [];
|
|
265
|
-
const mockRenderer = (props: any) => {
|
|
266
|
-
receivedProps.push(props);
|
|
267
|
-
return React.createElement(
|
|
268
|
-
"div",
|
|
269
|
-
{ "data-testid": "tool-render" },
|
|
270
|
-
`status: ${props.status}`,
|
|
271
|
-
);
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const toolMap = new Map([["myTool", mockRenderer]]);
|
|
275
|
-
hoisted.mockToolRegistry.mockReturnValue(toolMap);
|
|
276
|
-
|
|
277
|
-
// Add executing tool call ID to the shared set
|
|
278
|
-
hoisted.mockExecutingToolCallIds.add("tc-1");
|
|
279
|
-
|
|
280
|
-
hoisted.mockAgent.messages = [
|
|
281
|
-
{
|
|
282
|
-
id: "1",
|
|
283
|
-
role: "assistant",
|
|
284
|
-
content: "",
|
|
285
|
-
toolCalls: [
|
|
286
|
-
{
|
|
287
|
-
id: "tc-1",
|
|
288
|
-
type: "function" as const,
|
|
289
|
-
function: { name: "myTool", arguments: '{"key":"val"}' },
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
},
|
|
293
|
-
];
|
|
294
|
-
|
|
295
|
-
const { getByTestId } = render(<CopilotChat />);
|
|
296
|
-
|
|
297
|
-
expect(getByTestId("tool-render").textContent).toBe("status: executing");
|
|
298
|
-
expect(receivedProps[0].status).toBe("executing");
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
181
|
describe("message list building", () => {
|
|
303
182
|
it("handles assistant messages with empty content and tool calls", () => {
|
|
304
183
|
hoisted.mockAgent.messages = [
|
|
@@ -12,14 +12,18 @@ const hoisted = vi.hoisted(() => {
|
|
|
12
12
|
addMessage: vi.fn(),
|
|
13
13
|
},
|
|
14
14
|
mockRunAgent: vi.fn().mockResolvedValue(undefined),
|
|
15
|
-
mockToolRegistry: vi.fn(() => new Map()),
|
|
16
15
|
};
|
|
17
16
|
});
|
|
18
17
|
|
|
19
18
|
// ─── Mocks ────────────────────────────────────────────────────────────────────
|
|
20
19
|
|
|
20
|
+
// This suite mocks react-core wholesale to unit-test CopilotChat's non-tool
|
|
21
|
+
// behavior. Tool-call rendering (which drives a REAL useRenderToolCall) lives
|
|
22
|
+
// in CopilotChatToolCalls.test.tsx; here useRenderToolCall is a stub that
|
|
23
|
+
// resolves no renderer, so tool calls fall through to the placeholder.
|
|
21
24
|
vi.mock("@copilotkit/react-core/v2/headless", () => ({
|
|
22
25
|
useAgent: vi.fn(() => ({ agent: hoisted.mockAgent })),
|
|
26
|
+
useRenderToolCall: vi.fn(() => () => null),
|
|
23
27
|
}));
|
|
24
28
|
|
|
25
29
|
vi.mock("@copilotkit/react-core/v2/context", () => ({
|
|
@@ -52,11 +56,6 @@ vi.mock("../messages/UserMessage", () => ({
|
|
|
52
56
|
},
|
|
53
57
|
}));
|
|
54
58
|
|
|
55
|
-
// Mock RenderToolContext (B3)
|
|
56
|
-
vi.mock("../../hooks/RenderToolContext", () => ({
|
|
57
|
-
useRenderToolRegistry: () => hoisted.mockToolRegistry(),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
59
|
// Mock react-native components with testable DOM elements
|
|
61
60
|
vi.mock("react-native", () => {
|
|
62
61
|
const React = require("react");
|
|
@@ -140,7 +139,6 @@ describe("CopilotChat", () => {
|
|
|
140
139
|
hoisted.mockAgent.isRunning = false;
|
|
141
140
|
hoisted.mockAgent.addMessage = vi.fn();
|
|
142
141
|
hoisted.mockRunAgent.mockResolvedValue(undefined);
|
|
143
|
-
hoisted.mockToolRegistry.mockReturnValue(new Map());
|
|
144
142
|
});
|
|
145
143
|
|
|
146
144
|
it("renders empty state when there are no messages", () => {
|
|
@@ -303,48 +301,6 @@ describe("CopilotChat", () => {
|
|
|
303
301
|
expect(getByText("Called: myTool")).toBeTruthy();
|
|
304
302
|
});
|
|
305
303
|
|
|
306
|
-
it("renders registered tool renderer with correct props", () => {
|
|
307
|
-
const receivedProps: any[] = [];
|
|
308
|
-
const mockRenderer = (props: any) => {
|
|
309
|
-
receivedProps.push(props);
|
|
310
|
-
const React = require("react");
|
|
311
|
-
return React.createElement(
|
|
312
|
-
"div",
|
|
313
|
-
{ "data-testid": "tool-render" },
|
|
314
|
-
`rendered: ${JSON.stringify(props.args)}`,
|
|
315
|
-
);
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const toolMap = new Map([["myTool", mockRenderer]]);
|
|
319
|
-
hoisted.mockToolRegistry.mockReturnValue(toolMap);
|
|
320
|
-
|
|
321
|
-
hoisted.mockAgent.messages = [
|
|
322
|
-
{
|
|
323
|
-
id: "1",
|
|
324
|
-
role: "assistant",
|
|
325
|
-
content: "",
|
|
326
|
-
toolCalls: [
|
|
327
|
-
{
|
|
328
|
-
id: "tc-1",
|
|
329
|
-
type: "function" as const,
|
|
330
|
-
function: {
|
|
331
|
-
name: "myTool",
|
|
332
|
-
arguments: '{"city":"Seattle"}',
|
|
333
|
-
},
|
|
334
|
-
},
|
|
335
|
-
],
|
|
336
|
-
},
|
|
337
|
-
];
|
|
338
|
-
|
|
339
|
-
const { getByTestId } = render(<CopilotChat />);
|
|
340
|
-
|
|
341
|
-
expect(getByTestId("tool-render")).toBeTruthy();
|
|
342
|
-
expect(receivedProps[0]).toEqual({
|
|
343
|
-
args: { city: "Seattle" },
|
|
344
|
-
status: "complete",
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
304
|
it("shows error message when runAgent fails", async () => {
|
|
349
305
|
hoisted.mockRunAgent.mockRejectedValueOnce(new Error("Network timeout"));
|
|
350
306
|
|