@copilotkit/react-native 2.0.0-rc.2 → 2.0.0-rc.21
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/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-BXpkAl1Y.mjs} +55 -42
- package/dist/CopilotKitProvider-BXpkAl1Y.mjs.map +1 -0
- package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-DDPbJkHS.cjs} +53 -40
- package/dist/CopilotKitProvider-DDPbJkHS.cjs.map +1 -0
- package/dist/CopilotKitProvider-F7Pn5kp4.d.cts +65 -0
- package/dist/CopilotKitProvider-Khgz5dQo.d.mts +65 -0
- package/dist/{Markdown-C_9Re36O.cjs → Markdown-CaYHlD4j.cjs} +8 -8
- package/dist/Markdown-CaYHlD4j.cjs.map +1 -0
- package/dist/{Markdown-1ips7myr.d.cts → Markdown-DzjnSuu5.d.cts} +3 -3
- package/dist/{Markdown-C6AsLHmd.mjs → Markdown-SE9MfY2U.mjs} +4 -4
- package/dist/Markdown-SE9MfY2U.mjs.map +1 -0
- package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-a-rdG22_.d.mts} +3 -3
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-B_AKdPAN.mjs} +1 -1
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-B_AKdPAN.mjs.map} +1 -1
- package/dist/components/index.cjs +13 -4
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +14 -5
- package/dist/components/index.mjs.map +1 -1
- package/dist/headless.cjs +2 -1
- package/dist/headless.d.cts +2 -2
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -1
- package/dist/index.cjs +22 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -8
- package/dist/index.d.mts +23 -9
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +5 -5
- package/dist/polyfills/encoding.cjs.map +1 -1
- package/dist/polyfills/encoding.mjs +5 -4
- package/dist/polyfills/encoding.mjs.map +1 -1
- package/dist/polyfills.cjs +2 -1
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +2 -1
- package/dist/polyfills.mjs.map +1 -1
- package/dist/{streaming-fetch-Dm1oN4f2.mjs → streaming-fetch-CLHG3Z1H.mjs} +1 -1
- package/dist/{streaming-fetch-Dm1oN4f2.mjs.map → streaming-fetch-CLHG3Z1H.mjs.map} +1 -1
- package/dist/{streaming-fetch-Bm91EsRc.cjs → streaming-fetch-DbDALGya.cjs} +1 -1
- package/dist/{streaming-fetch-Bm91EsRc.cjs.map → streaming-fetch-DbDALGya.cjs.map} +1 -1
- package/dist/utf8-BIN9t4Oy.mjs +113 -0
- package/dist/utf8-BIN9t4Oy.mjs.map +1 -0
- package/dist/utf8-Cf3Ssy33.cjs +125 -0
- package/dist/utf8-Cf3Ssy33.cjs.map +1 -0
- package/package.json +11 -20
- package/scripts/verify-polyfill-barrel.mjs +4 -6
- package/src/CopilotChat.tsx +36 -9
- package/src/CopilotKitProvider.tsx +87 -130
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +4 -1
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/attachments-integration.test.tsx +15 -2
- package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
- package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- package/src/__tests__/copilot-popup.test.tsx +15 -2
- package/src/__tests__/copilot-sidebar.test.tsx +15 -2
- package/src/__tests__/copilotkit-provider.test.tsx +68 -73
- package/src/__tests__/headless-integration.test.tsx +11 -1
- package/src/components/CopilotChat.tsx +24 -3
- package/src/components/Markdown.tsx +4 -4
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
- package/src/components/__tests__/CopilotChat.test.tsx +5 -1
- package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
- package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
- package/src/components/messages/AssistantMessage.tsx +3 -2
- package/src/polyfills/__tests__/utf8.test.ts +112 -0
- package/src/polyfills/encoding.ts +5 -4
- package/src/polyfills/utf8.ts +151 -0
- package/src/types.d.ts +0 -13
- package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
- package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
- package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
- package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
- package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
- package/dist/Markdown-C_9Re36O.cjs.map +0 -1
|
@@ -33,6 +33,12 @@ function createMockCore() {
|
|
|
33
33
|
setMessageFilter: vi.fn(),
|
|
34
34
|
setDebug: vi.fn(),
|
|
35
35
|
setDefaultThrottleMs: vi.fn(),
|
|
36
|
+
ɵupdateConfig: vi.fn(),
|
|
37
|
+
ɵruntimeInfo: { status: "disconnected" },
|
|
38
|
+
ɵsubscribeToRuntimeInfo: vi.fn(() => () => {}),
|
|
39
|
+
setErrorHandler: vi.fn(),
|
|
40
|
+
connect: vi.fn(),
|
|
41
|
+
dispose: vi.fn(),
|
|
36
42
|
getAgent: vi.fn(() => undefined),
|
|
37
43
|
runtimeUrl: "https://api.test",
|
|
38
44
|
runtimeTransport: "auto",
|
|
@@ -52,13 +58,17 @@ function createMockCore() {
|
|
|
52
58
|
|
|
53
59
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
54
60
|
|
|
55
|
-
vi.mock("@copilotkit/react-core/headless", () => {
|
|
61
|
+
vi.mock("@copilotkit/react-core/headless", async (importOriginal) => {
|
|
62
|
+
// The real entry, so the provider gets the real `ɵuseOwnedCore`.
|
|
63
|
+
const actual =
|
|
64
|
+
await importOriginal<typeof import("@copilotkit/react-core/headless")>();
|
|
56
65
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
57
66
|
hoisted.MockCoreConstructor(...args);
|
|
58
67
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
59
68
|
if (instance) Object.assign(this, instance);
|
|
60
69
|
}
|
|
61
70
|
return {
|
|
71
|
+
...actual,
|
|
62
72
|
CopilotKitCoreReact,
|
|
63
73
|
useAgent: (props: any) => {
|
|
64
74
|
const ctx = require("react").useContext(hoisted.RealContext);
|
|
@@ -118,7 +128,10 @@ vi.mock("@copilotkit/react-core/context", () => {
|
|
|
118
128
|
};
|
|
119
129
|
});
|
|
120
130
|
|
|
121
|
-
vi.mock("@copilotkit/shared", () => ({
|
|
131
|
+
vi.mock("@copilotkit/shared", async (importOriginal) => ({
|
|
132
|
+
// The real module first: the provider evaluates @copilotkit/core, which
|
|
133
|
+
// needs shared's value exports.
|
|
134
|
+
...(await importOriginal<typeof import("@copilotkit/shared")>()),
|
|
122
135
|
DEFAULT_AGENT_ID: "default",
|
|
123
136
|
randomUUID: () => "test-uuid-" + Math.random().toString(36).slice(2, 8),
|
|
124
137
|
getModalityFromMimeType: (mimeType: string) => {
|
|
@@ -33,6 +33,12 @@ function createMockCore() {
|
|
|
33
33
|
setMessageFilter: vi.fn(),
|
|
34
34
|
setDebug: vi.fn(),
|
|
35
35
|
setDefaultThrottleMs: vi.fn(),
|
|
36
|
+
ɵupdateConfig: vi.fn(),
|
|
37
|
+
ɵruntimeInfo: { status: "disconnected" },
|
|
38
|
+
ɵsubscribeToRuntimeInfo: vi.fn(() => () => {}),
|
|
39
|
+
setErrorHandler: vi.fn(),
|
|
40
|
+
connect: vi.fn(),
|
|
41
|
+
dispose: vi.fn(),
|
|
36
42
|
getAgent: vi.fn(() => undefined),
|
|
37
43
|
runtimeUrl: "https://api.test",
|
|
38
44
|
runtimeTransport: "auto",
|
|
@@ -52,13 +58,17 @@ function createMockCore() {
|
|
|
52
58
|
|
|
53
59
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
54
60
|
|
|
55
|
-
vi.mock("@copilotkit/react-core/headless", () => {
|
|
61
|
+
vi.mock("@copilotkit/react-core/headless", async (importOriginal) => {
|
|
62
|
+
// The real entry, so the provider gets the real `ɵuseOwnedCore`.
|
|
63
|
+
const actual =
|
|
64
|
+
await importOriginal<typeof import("@copilotkit/react-core/headless")>();
|
|
56
65
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
57
66
|
hoisted.MockCoreConstructor(...args);
|
|
58
67
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
59
68
|
if (instance) Object.assign(this, instance);
|
|
60
69
|
}
|
|
61
70
|
return {
|
|
71
|
+
...actual,
|
|
62
72
|
CopilotKitCoreReact,
|
|
63
73
|
useAgent: (props: any) => {
|
|
64
74
|
const ctx = require("react").useContext(hoisted.RealContext);
|
|
@@ -118,7 +128,10 @@ vi.mock("@copilotkit/react-core/context", () => {
|
|
|
118
128
|
};
|
|
119
129
|
});
|
|
120
130
|
|
|
121
|
-
vi.mock("@copilotkit/shared", () => ({
|
|
131
|
+
vi.mock("@copilotkit/shared", async (importOriginal) => ({
|
|
132
|
+
// The real module first: the provider evaluates @copilotkit/core, which
|
|
133
|
+
// needs shared's value exports.
|
|
134
|
+
...(await importOriginal<typeof import("@copilotkit/shared")>()),
|
|
122
135
|
DEFAULT_AGENT_ID: "default",
|
|
123
136
|
randomUUID: () => "test-uuid-" + Math.random().toString(36).slice(2, 8),
|
|
124
137
|
getModalityFromMimeType: (mimeType: string) => {
|
|
@@ -23,17 +23,20 @@ function createMockCore() {
|
|
|
23
23
|
capturedSubscriber = subscriber;
|
|
24
24
|
return { unsubscribe: unsubscribeMock };
|
|
25
25
|
}),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
setDebug: vi.fn(),
|
|
33
|
-
setDefaultThrottleMs: vi.fn(),
|
|
26
|
+
ɵupdateConfig: vi.fn(),
|
|
27
|
+
ɵruntimeInfo: { status: "disconnected" },
|
|
28
|
+
ɵsubscribeToRuntimeInfo: vi.fn(() => () => {}),
|
|
29
|
+
setErrorHandler: vi.fn(),
|
|
30
|
+
connect: vi.fn(),
|
|
31
|
+
dispose: vi.fn(),
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
34
|
|
|
35
|
+
/** The last config patch the provider pushed to the core. */
|
|
36
|
+
function lastPatch() {
|
|
37
|
+
return mockCoreInstance.ɵupdateConfig.mock.calls.at(-1)?.[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
37
40
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
38
41
|
|
|
39
42
|
/** Keeps the final turn only — the shape #1482 asks for. */
|
|
@@ -41,14 +44,16 @@ const keepLastTurn = (messages: any[]) => messages.slice(-1);
|
|
|
41
44
|
/** A second, distinguishable filter, for asserting a swap took effect. */
|
|
42
45
|
const keepLastTwo = (messages: any[]) => messages.slice(-2);
|
|
43
46
|
|
|
44
|
-
vi.mock("@copilotkit/react-core/headless", () => {
|
|
47
|
+
vi.mock("@copilotkit/react-core/headless", async (importOriginal) => {
|
|
48
|
+
const actual =
|
|
49
|
+
await importOriginal<typeof import("@copilotkit/react-core/headless")>();
|
|
45
50
|
// Regular function (not arrow) so it's new-able
|
|
46
51
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
47
52
|
hoisted.MockCoreConstructor(...args);
|
|
48
53
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
49
54
|
if (instance) Object.assign(this, instance);
|
|
50
55
|
}
|
|
51
|
-
return { CopilotKitCoreReact };
|
|
56
|
+
return { ...actual, CopilotKitCoreReact };
|
|
52
57
|
});
|
|
53
58
|
|
|
54
59
|
vi.mock("@copilotkit/react-core/context", () => {
|
|
@@ -70,7 +75,8 @@ vi.mock("@copilotkit/react-core/context", () => {
|
|
|
70
75
|
};
|
|
71
76
|
});
|
|
72
77
|
|
|
73
|
-
vi.mock("@copilotkit/shared", () => ({
|
|
78
|
+
vi.mock("@copilotkit/shared", async (importOriginal) => ({
|
|
79
|
+
...(await importOriginal<typeof import("@copilotkit/shared")>()),
|
|
74
80
|
createLicenseContextValue: () => ({
|
|
75
81
|
status: null,
|
|
76
82
|
license: null,
|
|
@@ -197,9 +203,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
197
203
|
</CopilotKitProvider>,
|
|
198
204
|
);
|
|
199
205
|
|
|
200
|
-
expect(
|
|
201
|
-
"https://api.test/v2",
|
|
202
|
-
);
|
|
206
|
+
expect(lastPatch()?.runtimeUrl).toBe("https://api.test/v2");
|
|
203
207
|
});
|
|
204
208
|
|
|
205
209
|
it("calls setHeaders when headers content changes", () => {
|
|
@@ -209,7 +213,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
209
213
|
</CopilotKitProvider>,
|
|
210
214
|
);
|
|
211
215
|
|
|
212
|
-
mockCoreInstance.
|
|
216
|
+
mockCoreInstance.ɵupdateConfig.mockClear();
|
|
213
217
|
|
|
214
218
|
rerender(
|
|
215
219
|
<CopilotKitProvider runtimeUrl="https://api.test" headers={{ b: "2" }}>
|
|
@@ -217,7 +221,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
217
221
|
</CopilotKitProvider>,
|
|
218
222
|
);
|
|
219
223
|
|
|
220
|
-
expect(
|
|
224
|
+
expect(lastPatch()?.headers).toEqual({ b: "2" });
|
|
221
225
|
});
|
|
222
226
|
|
|
223
227
|
it("does not re-fire setHeaders when content is identical (JSON-stabilized)", () => {
|
|
@@ -227,7 +231,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
227
231
|
</CopilotKitProvider>,
|
|
228
232
|
);
|
|
229
233
|
|
|
230
|
-
mockCoreInstance.
|
|
234
|
+
mockCoreInstance.ɵupdateConfig.mockClear();
|
|
231
235
|
|
|
232
236
|
// New object reference but same content
|
|
233
237
|
rerender(
|
|
@@ -236,7 +240,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
236
240
|
</CopilotKitProvider>,
|
|
237
241
|
);
|
|
238
242
|
|
|
239
|
-
expect(mockCoreInstance
|
|
243
|
+
expect(mockCoreInstance.ɵupdateConfig).not.toHaveBeenCalled();
|
|
240
244
|
});
|
|
241
245
|
|
|
242
246
|
// #1482: parity with the React, Vue and Angular providers. The filter's own
|
|
@@ -267,7 +271,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
267
271
|
</CopilotKitProvider>,
|
|
268
272
|
);
|
|
269
273
|
|
|
270
|
-
mockCoreInstance.
|
|
274
|
+
mockCoreInstance.ɵupdateConfig.mockClear();
|
|
271
275
|
|
|
272
276
|
rerender(
|
|
273
277
|
<CopilotKitProvider
|
|
@@ -278,9 +282,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
278
282
|
</CopilotKitProvider>,
|
|
279
283
|
);
|
|
280
284
|
|
|
281
|
-
expect(
|
|
282
|
-
keepLastTwo,
|
|
283
|
-
);
|
|
285
|
+
expect(lastPatch()?.messageFilter).toBe(keepLastTwo);
|
|
284
286
|
});
|
|
285
287
|
|
|
286
288
|
it("clears the filter when the prop goes away", () => {
|
|
@@ -293,7 +295,7 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
293
295
|
</CopilotKitProvider>,
|
|
294
296
|
);
|
|
295
297
|
|
|
296
|
-
mockCoreInstance.
|
|
298
|
+
mockCoreInstance.ɵupdateConfig.mockClear();
|
|
297
299
|
|
|
298
300
|
rerender(
|
|
299
301
|
<CopilotKitProvider runtimeUrl="https://api.test">
|
|
@@ -301,7 +303,9 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
301
303
|
</CopilotKitProvider>,
|
|
302
304
|
);
|
|
303
305
|
|
|
304
|
-
|
|
306
|
+
const patch = lastPatch();
|
|
307
|
+
expect(patch && "messageFilter" in patch).toBe(true);
|
|
308
|
+
expect(patch?.messageFilter).toBeUndefined();
|
|
305
309
|
});
|
|
306
310
|
});
|
|
307
311
|
|
|
@@ -403,7 +407,9 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
403
407
|
// ── Error handling ────────────────────────────────────────────────────
|
|
404
408
|
|
|
405
409
|
describe("error handling", () => {
|
|
406
|
-
|
|
410
|
+
// Core calls the handler, and logs when there is none (core tests cover
|
|
411
|
+
// that). The provider's job is handing the handler over.
|
|
412
|
+
it("passes onError to the core at construction", () => {
|
|
407
413
|
const onError = vi.fn();
|
|
408
414
|
render(
|
|
409
415
|
<CopilotKitProvider runtimeUrl="https://api.test" onError={onError}>
|
|
@@ -411,47 +417,12 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
411
417
|
</CopilotKitProvider>,
|
|
412
418
|
);
|
|
413
419
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
capturedSubscriber.onError({
|
|
417
|
-
error: testError,
|
|
418
|
-
code: "RUNTIME_ERROR",
|
|
419
|
-
context: { detail: "info" },
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
expect(onError).toHaveBeenCalledWith({
|
|
424
|
-
error: testError,
|
|
425
|
-
code: "RUNTIME_ERROR",
|
|
426
|
-
context: { detail: "info" },
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("logs to console.error when onError is not provided", () => {
|
|
431
|
-
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
432
|
-
render(
|
|
433
|
-
<CopilotKitProvider runtimeUrl="https://api.test">
|
|
434
|
-
<div />
|
|
435
|
-
</CopilotKitProvider>,
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
act(() => {
|
|
439
|
-
capturedSubscriber.onError({
|
|
440
|
-
error: new Error("fail"),
|
|
441
|
-
code: "AGENT_ERROR",
|
|
442
|
-
context: {},
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
expect(spy).toHaveBeenCalledWith(
|
|
447
|
-
expect.stringContaining("AGENT_ERROR"),
|
|
448
|
-
expect.any(Error),
|
|
449
|
-
expect.any(Object),
|
|
420
|
+
expect(hoisted.MockCoreConstructor).toHaveBeenCalledWith(
|
|
421
|
+
expect.objectContaining({ onError }),
|
|
450
422
|
);
|
|
451
|
-
spy.mockRestore();
|
|
452
423
|
});
|
|
453
424
|
|
|
454
|
-
it("
|
|
425
|
+
it("hands a new onError to the core", () => {
|
|
455
426
|
const onError1 = vi.fn();
|
|
456
427
|
const onError2 = vi.fn();
|
|
457
428
|
|
|
@@ -467,16 +438,9 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
467
438
|
</CopilotKitProvider>,
|
|
468
439
|
);
|
|
469
440
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
code: "RUNTIME_ERROR",
|
|
474
|
-
context: {},
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
expect(onError1).not.toHaveBeenCalled();
|
|
479
|
-
expect(onError2).toHaveBeenCalled();
|
|
441
|
+
expect(mockCoreInstance.setErrorHandler).toHaveBeenLastCalledWith(
|
|
442
|
+
onError2,
|
|
443
|
+
);
|
|
480
444
|
});
|
|
481
445
|
});
|
|
482
446
|
|
|
@@ -494,5 +458,36 @@ describe("CopilotKitProvider (React Native)", () => {
|
|
|
494
458
|
|
|
495
459
|
expect(unsubscribeMock).toHaveBeenCalled();
|
|
496
460
|
});
|
|
461
|
+
|
|
462
|
+
it("disposes the core after unmount", async () => {
|
|
463
|
+
const { unmount } = render(
|
|
464
|
+
<CopilotKitProvider runtimeUrl="https://api.test">
|
|
465
|
+
<div />
|
|
466
|
+
</CopilotKitProvider>,
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
unmount();
|
|
470
|
+
|
|
471
|
+
await vi.waitFor(() =>
|
|
472
|
+
expect(mockCoreInstance.dispose).toHaveBeenCalledTimes(1),
|
|
473
|
+
);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// ── Runtime connection ──────────────────────────────────────────────
|
|
478
|
+
|
|
479
|
+
describe("runtime connection", () => {
|
|
480
|
+
it("defers /info to an effect", () => {
|
|
481
|
+
render(
|
|
482
|
+
<CopilotKitProvider runtimeUrl="https://api.test">
|
|
483
|
+
<div />
|
|
484
|
+
</CopilotKitProvider>,
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
expect(hoisted.MockCoreConstructor).toHaveBeenCalledWith(
|
|
488
|
+
expect.objectContaining({ deferInitialConnection: true }),
|
|
489
|
+
);
|
|
490
|
+
expect(mockCoreInstance.connect).toHaveBeenCalled();
|
|
491
|
+
});
|
|
497
492
|
});
|
|
498
493
|
});
|
|
@@ -88,6 +88,12 @@ function createMockCore() {
|
|
|
88
88
|
setMessageFilter: vi.fn(),
|
|
89
89
|
setDebug: vi.fn(),
|
|
90
90
|
setDefaultThrottleMs: vi.fn(),
|
|
91
|
+
ɵupdateConfig: vi.fn(),
|
|
92
|
+
ɵruntimeInfo: { status: "disconnected" },
|
|
93
|
+
ɵsubscribeToRuntimeInfo: vi.fn(() => () => {}),
|
|
94
|
+
setErrorHandler: vi.fn(),
|
|
95
|
+
connect: vi.fn(),
|
|
96
|
+
dispose: vi.fn(),
|
|
91
97
|
getAgent: vi.fn(() => undefined),
|
|
92
98
|
runtimeUrl: "https://api.test",
|
|
93
99
|
runtimeTransport: "auto",
|
|
@@ -107,7 +113,10 @@ function createMockCore() {
|
|
|
107
113
|
|
|
108
114
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
109
115
|
|
|
110
|
-
vi.mock("@copilotkit/react-core/headless", () => {
|
|
116
|
+
vi.mock("@copilotkit/react-core/headless", async (importOriginal) => {
|
|
117
|
+
// The real entry, so the provider gets the real `ɵuseOwnedCore`.
|
|
118
|
+
const actual =
|
|
119
|
+
await importOriginal<typeof import("@copilotkit/react-core/headless")>();
|
|
111
120
|
// Regular function (not arrow) so it's new-able
|
|
112
121
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
113
122
|
hoisted.MockCoreConstructor(...args);
|
|
@@ -115,6 +124,7 @@ vi.mock("@copilotkit/react-core/headless", () => {
|
|
|
115
124
|
if (instance) Object.assign(this, instance);
|
|
116
125
|
}
|
|
117
126
|
return {
|
|
127
|
+
...actual,
|
|
118
128
|
CopilotKitCoreReact,
|
|
119
129
|
useAgent: () => {
|
|
120
130
|
const ctx = require("react").useContext(hoisted.RealContext);
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
2
8
|
import {
|
|
3
9
|
FlatList,
|
|
4
10
|
KeyboardAvoidingView,
|
|
@@ -286,6 +292,20 @@ export function CopilotChat({
|
|
|
286
292
|
|
|
287
293
|
const renderToolCall = useRenderToolCall();
|
|
288
294
|
|
|
295
|
+
// useInterrupt publishes its element to core unless renderInChat is false.
|
|
296
|
+
// Draw it after the last message, as the web message view does.
|
|
297
|
+
const [interruptElement, setInterruptElement] =
|
|
298
|
+
useState<React.ReactElement | null>(null);
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
setInterruptElement(copilotkit.interruptElement);
|
|
301
|
+
const subscription = copilotkit.subscribe({
|
|
302
|
+
onInterruptElementChanged: ({ interruptElement: element }) => {
|
|
303
|
+
setInterruptElement(element);
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
return () => subscription.unsubscribe();
|
|
307
|
+
}, [copilotkit]);
|
|
308
|
+
|
|
289
309
|
// Recomputed every render — cheap, and the only honest dependency for the
|
|
290
310
|
// message-derived memos below. See `messagesFingerprint` for why the array
|
|
291
311
|
// reference cannot be trusted as one.
|
|
@@ -416,11 +436,11 @@ export function CopilotChat({
|
|
|
416
436
|
);
|
|
417
437
|
|
|
418
438
|
// Send from the input field
|
|
419
|
-
const handleSend = useCallback(
|
|
439
|
+
const handleSend = useCallback(() => {
|
|
420
440
|
const text = inputText.trim();
|
|
421
441
|
if (!text) return;
|
|
422
442
|
setInputText("");
|
|
423
|
-
|
|
443
|
+
void sendMessage(text);
|
|
424
444
|
}, [inputText, sendMessage]);
|
|
425
445
|
|
|
426
446
|
// Handle suggestion pill press
|
|
@@ -522,6 +542,7 @@ export function CopilotChat({
|
|
|
522
542
|
contentContainerStyle={[styles.messageList, messageContainerStyle]}
|
|
523
543
|
onContentSizeChange={handleContentSizeChange}
|
|
524
544
|
ListEmptyComponent={emptyComponent}
|
|
545
|
+
ListFooterComponent={interruptElement}
|
|
525
546
|
/>
|
|
526
547
|
|
|
527
548
|
{error && (
|
|
@@ -2,9 +2,9 @@ import React from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
StreamingMarkdownRenderer,
|
|
4
4
|
defaultMarkdownStyles as _streamingDefaultStyles,
|
|
5
|
-
} from "@copilotkit/markdown
|
|
6
|
-
import type { MarkdownStyle as StreamingMarkdownStyle } from "@copilotkit/markdown
|
|
7
|
-
import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown
|
|
5
|
+
} from "@copilotkit/markdown/react-native";
|
|
6
|
+
import type { MarkdownStyle as StreamingMarkdownStyle } from "@copilotkit/markdown/react-native";
|
|
7
|
+
import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Style map for CopilotMarkdown. Each key maps a node type to a React Native
|
|
@@ -45,7 +45,7 @@ export interface CopilotMarkdownProps {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* GFM markdown renderer for React Native. Delegates to the shared
|
|
48
|
-
* `StreamingMarkdownRenderer` from `@copilotkit/markdown
|
|
48
|
+
* `StreamingMarkdownRenderer` from `@copilotkit/markdown/react-native`.
|
|
49
49
|
*
|
|
50
50
|
* Public API is backward-compatible with the previous basic renderer:
|
|
51
51
|
* - `CopilotMarkdownProps` — same shape.
|
|
@@ -29,7 +29,11 @@ vi.mock("@copilotkit/react-core/headless", () => ({
|
|
|
29
29
|
|
|
30
30
|
vi.mock("@copilotkit/react-core/context", () => ({
|
|
31
31
|
useCopilotKit: vi.fn(() => ({
|
|
32
|
-
copilotkit: {
|
|
32
|
+
copilotkit: {
|
|
33
|
+
runAgent: hoisted.mockRunAgent,
|
|
34
|
+
interruptElement: null,
|
|
35
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
36
|
+
},
|
|
33
37
|
executingToolCallIds: hoisted.mockExecutingToolCallIds,
|
|
34
38
|
})),
|
|
35
39
|
}));
|
|
@@ -28,7 +28,11 @@ vi.mock("@copilotkit/react-core/headless", () => ({
|
|
|
28
28
|
|
|
29
29
|
vi.mock("@copilotkit/react-core/context", () => ({
|
|
30
30
|
useCopilotKit: vi.fn(() => ({
|
|
31
|
-
copilotkit: {
|
|
31
|
+
copilotkit: {
|
|
32
|
+
runAgent: hoisted.mockRunAgent,
|
|
33
|
+
interruptElement: null,
|
|
34
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
35
|
+
},
|
|
32
36
|
executingToolCallIds: new Set<string>(),
|
|
33
37
|
})),
|
|
34
38
|
}));
|