@copilotkit/react-native 2.0.0-rc.2 → 2.0.0-rc.20
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-Byw3cqe2.cjs → CopilotKitProvider-DbI3aQam.cjs} +1 -1
- package/dist/CopilotKitProvider-DbI3aQam.cjs.map +1 -0
- package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-DlP73sLt.mjs} +2 -2
- package/dist/CopilotKitProvider-DlP73sLt.mjs.map +1 -0
- package/dist/{CopilotKitProvider-BWjzCdHN.d.mts → CopilotKitProvider-lfVMYSby.d.cts} +5 -4
- package/dist/{CopilotKitProvider-Btm10msB.d.cts → CopilotKitProvider-mVDI6DLx.d.mts} +5 -4
- 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 +22 -8
- 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 +3 -2
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +4 -1
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- 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-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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//#region src/polyfills/utf8.ts
|
|
2
|
+
/**
|
|
3
|
+
* UTF-8 `TextEncoder` and `TextDecoder`, for runtimes that have neither.
|
|
4
|
+
*
|
|
5
|
+
* CopilotKit only reads and writes UTF-8, so these classes support only that
|
|
6
|
+
* encoding. The decoder follows the WHATWG UTF-8 decode algorithm, so its
|
|
7
|
+
* output, including U+FFFD for invalid bytes and `{ stream: true }` chunks,
|
|
8
|
+
* matches the built-in `TextDecoder`.
|
|
9
|
+
*/
|
|
10
|
+
const REPLACEMENT = 65533;
|
|
11
|
+
var Utf8TextEncoder = class {
|
|
12
|
+
encoding = "utf-8";
|
|
13
|
+
encode(input = "") {
|
|
14
|
+
const bytes = [];
|
|
15
|
+
for (const char of input) {
|
|
16
|
+
let codePoint = char.codePointAt(0);
|
|
17
|
+
if (codePoint >= 55296 && codePoint <= 57343) codePoint = REPLACEMENT;
|
|
18
|
+
if (codePoint < 128) bytes.push(codePoint);
|
|
19
|
+
else if (codePoint < 2048) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
|
|
20
|
+
else if (codePoint < 65536) bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
|
|
21
|
+
else bytes.push(240 | codePoint >> 18, 128 | codePoint >> 12 & 63, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
|
|
22
|
+
}
|
|
23
|
+
return new Uint8Array(bytes);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var Utf8TextDecoder = class {
|
|
27
|
+
encoding = "utf-8";
|
|
28
|
+
fatal;
|
|
29
|
+
ignoreBOM;
|
|
30
|
+
#codePoint = 0;
|
|
31
|
+
#bytesNeeded = 0;
|
|
32
|
+
#bytesSeen = 0;
|
|
33
|
+
#lowerBoundary = 128;
|
|
34
|
+
#upperBoundary = 191;
|
|
35
|
+
#atStart = true;
|
|
36
|
+
constructor(label = "utf-8", options = {}) {
|
|
37
|
+
const normalized = String(label).trim().toLowerCase();
|
|
38
|
+
if (normalized !== "utf-8" && normalized !== "utf8") throw new RangeError(`The "${label}" encoding is not supported.`);
|
|
39
|
+
this.fatal = options.fatal ?? false;
|
|
40
|
+
this.ignoreBOM = options.ignoreBOM ?? false;
|
|
41
|
+
}
|
|
42
|
+
decode(input, options = {}) {
|
|
43
|
+
const bytes = input === void 0 ? new Uint8Array(0) : ArrayBuffer.isView(input) ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength) : new Uint8Array(input);
|
|
44
|
+
const codePoints = [];
|
|
45
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
46
|
+
const byte = bytes[i];
|
|
47
|
+
if (this.#bytesNeeded === 0) {
|
|
48
|
+
if (byte <= 127) codePoints.push(byte);
|
|
49
|
+
else if (byte >= 194 && byte <= 223) this.#start(1, byte & 31);
|
|
50
|
+
else if (byte >= 224 && byte <= 239) {
|
|
51
|
+
if (byte === 224) this.#lowerBoundary = 160;
|
|
52
|
+
if (byte === 237) this.#upperBoundary = 159;
|
|
53
|
+
this.#start(2, byte & 15);
|
|
54
|
+
} else if (byte >= 240 && byte <= 244) {
|
|
55
|
+
if (byte === 240) this.#lowerBoundary = 144;
|
|
56
|
+
if (byte === 244) this.#upperBoundary = 143;
|
|
57
|
+
this.#start(3, byte & 7);
|
|
58
|
+
} else codePoints.push(this.#error());
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (byte < this.#lowerBoundary || byte > this.#upperBoundary) {
|
|
62
|
+
this.#reset();
|
|
63
|
+
codePoints.push(this.#error());
|
|
64
|
+
i--;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
this.#lowerBoundary = 128;
|
|
68
|
+
this.#upperBoundary = 191;
|
|
69
|
+
this.#codePoint = this.#codePoint << 6 | byte & 63;
|
|
70
|
+
if (++this.#bytesSeen === this.#bytesNeeded) {
|
|
71
|
+
codePoints.push(this.#codePoint);
|
|
72
|
+
this.#reset();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!options.stream && this.#bytesNeeded > 0) {
|
|
76
|
+
this.#reset();
|
|
77
|
+
codePoints.push(this.#error());
|
|
78
|
+
}
|
|
79
|
+
if (this.#atStart && codePoints.length > 0) {
|
|
80
|
+
this.#atStart = false;
|
|
81
|
+
if (!this.ignoreBOM && codePoints[0] === 65279) codePoints.shift();
|
|
82
|
+
}
|
|
83
|
+
if (!options.stream) this.#atStart = true;
|
|
84
|
+
return codePointsToString(codePoints);
|
|
85
|
+
}
|
|
86
|
+
#start(bytesNeeded, codePoint) {
|
|
87
|
+
this.#bytesNeeded = bytesNeeded;
|
|
88
|
+
this.#codePoint = codePoint;
|
|
89
|
+
}
|
|
90
|
+
#reset() {
|
|
91
|
+
this.#codePoint = 0;
|
|
92
|
+
this.#bytesNeeded = 0;
|
|
93
|
+
this.#bytesSeen = 0;
|
|
94
|
+
this.#lowerBoundary = 128;
|
|
95
|
+
this.#upperBoundary = 191;
|
|
96
|
+
}
|
|
97
|
+
#error() {
|
|
98
|
+
if (this.fatal) {
|
|
99
|
+
this.#atStart = true;
|
|
100
|
+
throw new TypeError("The encoded data was not valid utf-8.");
|
|
101
|
+
}
|
|
102
|
+
return REPLACEMENT;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function codePointsToString(codePoints) {
|
|
106
|
+
let out = "";
|
|
107
|
+
for (let i = 0; i < codePoints.length; i += 32768) out += String.fromCodePoint(...codePoints.slice(i, i + 32768));
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { Utf8TextEncoder as n, Utf8TextDecoder as t };
|
|
113
|
+
//# sourceMappingURL=utf8-BIN9t4Oy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-BIN9t4Oy.mjs","names":["#bytesNeeded","#start","#lowerBoundary","#upperBoundary","#error","#reset","#codePoint","#bytesSeen","#atStart"],"sources":["../src/polyfills/utf8.ts"],"sourcesContent":["/**\n * UTF-8 `TextEncoder` and `TextDecoder`, for runtimes that have neither.\n *\n * CopilotKit only reads and writes UTF-8, so these classes support only that\n * encoding. The decoder follows the WHATWG UTF-8 decode algorithm, so its\n * output, including U+FFFD for invalid bytes and `{ stream: true }` chunks,\n * matches the built-in `TextDecoder`.\n */\n\nconst REPLACEMENT = 0xfffd;\n\nexport class Utf8TextEncoder {\n readonly encoding = \"utf-8\";\n\n encode(input = \"\"): Uint8Array {\n const bytes: number[] = [];\n for (const char of input) {\n let codePoint = char.codePointAt(0)!;\n // A lone surrogate is not a Unicode scalar value.\n if (codePoint >= 0xd800 && codePoint <= 0xdfff) codePoint = REPLACEMENT;\n if (codePoint < 0x80) bytes.push(codePoint);\n else if (codePoint < 0x800)\n bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));\n else if (codePoint < 0x10000)\n bytes.push(\n 0xe0 | (codePoint >> 12),\n 0x80 | ((codePoint >> 6) & 0x3f),\n 0x80 | (codePoint & 0x3f),\n );\n else\n bytes.push(\n 0xf0 | (codePoint >> 18),\n 0x80 | ((codePoint >> 12) & 0x3f),\n 0x80 | ((codePoint >> 6) & 0x3f),\n 0x80 | (codePoint & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n}\n\nexport class Utf8TextDecoder {\n readonly encoding = \"utf-8\";\n readonly fatal: boolean;\n readonly ignoreBOM: boolean;\n\n #codePoint = 0;\n #bytesNeeded = 0;\n #bytesSeen = 0;\n #lowerBoundary = 0x80;\n #upperBoundary = 0xbf;\n #atStart = true;\n\n constructor(\n label = \"utf-8\",\n options: { fatal?: boolean; ignoreBOM?: boolean } = {},\n ) {\n const normalized = String(label).trim().toLowerCase();\n if (normalized !== \"utf-8\" && normalized !== \"utf8\") {\n throw new RangeError(`The \"${label}\" encoding is not supported.`);\n }\n this.fatal = options.fatal ?? false;\n this.ignoreBOM = options.ignoreBOM ?? false;\n }\n\n decode(\n input?: ArrayBuffer | ArrayBufferView,\n options: { stream?: boolean } = {},\n ): string {\n const bytes =\n input === undefined\n ? new Uint8Array(0)\n : ArrayBuffer.isView(input)\n ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)\n : new Uint8Array(input);\n const codePoints: number[] = [];\n\n for (let i = 0; i < bytes.length; i++) {\n const byte = bytes[i];\n if (this.#bytesNeeded === 0) {\n if (byte <= 0x7f) codePoints.push(byte);\n else if (byte >= 0xc2 && byte <= 0xdf) this.#start(1, byte & 0x1f);\n else if (byte >= 0xe0 && byte <= 0xef) {\n if (byte === 0xe0) this.#lowerBoundary = 0xa0;\n if (byte === 0xed) this.#upperBoundary = 0x9f;\n this.#start(2, byte & 0x0f);\n } else if (byte >= 0xf0 && byte <= 0xf4) {\n if (byte === 0xf0) this.#lowerBoundary = 0x90;\n if (byte === 0xf4) this.#upperBoundary = 0x8f;\n this.#start(3, byte & 0x07);\n } else codePoints.push(this.#error());\n continue;\n }\n if (byte < this.#lowerBoundary || byte > this.#upperBoundary) {\n // The sequence ends early. Read this byte again as a new sequence.\n this.#reset();\n codePoints.push(this.#error());\n i--;\n continue;\n }\n this.#lowerBoundary = 0x80;\n this.#upperBoundary = 0xbf;\n this.#codePoint = (this.#codePoint << 6) | (byte & 0x3f);\n if (++this.#bytesSeen === this.#bytesNeeded) {\n codePoints.push(this.#codePoint);\n this.#reset();\n }\n }\n\n if (!options.stream && this.#bytesNeeded > 0) {\n this.#reset();\n codePoints.push(this.#error());\n }\n if (this.#atStart && codePoints.length > 0) {\n this.#atStart = false;\n if (!this.ignoreBOM && codePoints[0] === 0xfeff) codePoints.shift();\n }\n if (!options.stream) this.#atStart = true;\n return codePointsToString(codePoints);\n }\n\n #start(bytesNeeded: number, codePoint: number): void {\n this.#bytesNeeded = bytesNeeded;\n this.#codePoint = codePoint;\n }\n\n #reset(): void {\n this.#codePoint = 0;\n this.#bytesNeeded = 0;\n this.#bytesSeen = 0;\n this.#lowerBoundary = 0x80;\n this.#upperBoundary = 0xbf;\n }\n\n #error(): number {\n if (this.fatal) {\n this.#atStart = true;\n throw new TypeError(\"The encoded data was not valid utf-8.\");\n }\n return REPLACEMENT;\n }\n}\n\nfunction codePointsToString(codePoints: number[]): string {\n let out = \"\";\n // Stay under the engine's limit on function arguments.\n for (let i = 0; i < codePoints.length; i += 0x8000) {\n out += String.fromCodePoint(...codePoints.slice(i, i + 0x8000));\n }\n return out;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/polyfills/utf8.ts
|
|
3
|
+
/**
|
|
4
|
+
* UTF-8 `TextEncoder` and `TextDecoder`, for runtimes that have neither.
|
|
5
|
+
*
|
|
6
|
+
* CopilotKit only reads and writes UTF-8, so these classes support only that
|
|
7
|
+
* encoding. The decoder follows the WHATWG UTF-8 decode algorithm, so its
|
|
8
|
+
* output, including U+FFFD for invalid bytes and `{ stream: true }` chunks,
|
|
9
|
+
* matches the built-in `TextDecoder`.
|
|
10
|
+
*/
|
|
11
|
+
const REPLACEMENT = 65533;
|
|
12
|
+
var Utf8TextEncoder = class {
|
|
13
|
+
encoding = "utf-8";
|
|
14
|
+
encode(input = "") {
|
|
15
|
+
const bytes = [];
|
|
16
|
+
for (const char of input) {
|
|
17
|
+
let codePoint = char.codePointAt(0);
|
|
18
|
+
if (codePoint >= 55296 && codePoint <= 57343) codePoint = REPLACEMENT;
|
|
19
|
+
if (codePoint < 128) bytes.push(codePoint);
|
|
20
|
+
else if (codePoint < 2048) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
|
|
21
|
+
else if (codePoint < 65536) bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
|
|
22
|
+
else bytes.push(240 | codePoint >> 18, 128 | codePoint >> 12 & 63, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
|
|
23
|
+
}
|
|
24
|
+
return new Uint8Array(bytes);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var Utf8TextDecoder = class {
|
|
28
|
+
encoding = "utf-8";
|
|
29
|
+
fatal;
|
|
30
|
+
ignoreBOM;
|
|
31
|
+
#codePoint = 0;
|
|
32
|
+
#bytesNeeded = 0;
|
|
33
|
+
#bytesSeen = 0;
|
|
34
|
+
#lowerBoundary = 128;
|
|
35
|
+
#upperBoundary = 191;
|
|
36
|
+
#atStart = true;
|
|
37
|
+
constructor(label = "utf-8", options = {}) {
|
|
38
|
+
const normalized = String(label).trim().toLowerCase();
|
|
39
|
+
if (normalized !== "utf-8" && normalized !== "utf8") throw new RangeError(`The "${label}" encoding is not supported.`);
|
|
40
|
+
this.fatal = options.fatal ?? false;
|
|
41
|
+
this.ignoreBOM = options.ignoreBOM ?? false;
|
|
42
|
+
}
|
|
43
|
+
decode(input, options = {}) {
|
|
44
|
+
const bytes = input === void 0 ? new Uint8Array(0) : ArrayBuffer.isView(input) ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength) : new Uint8Array(input);
|
|
45
|
+
const codePoints = [];
|
|
46
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
47
|
+
const byte = bytes[i];
|
|
48
|
+
if (this.#bytesNeeded === 0) {
|
|
49
|
+
if (byte <= 127) codePoints.push(byte);
|
|
50
|
+
else if (byte >= 194 && byte <= 223) this.#start(1, byte & 31);
|
|
51
|
+
else if (byte >= 224 && byte <= 239) {
|
|
52
|
+
if (byte === 224) this.#lowerBoundary = 160;
|
|
53
|
+
if (byte === 237) this.#upperBoundary = 159;
|
|
54
|
+
this.#start(2, byte & 15);
|
|
55
|
+
} else if (byte >= 240 && byte <= 244) {
|
|
56
|
+
if (byte === 240) this.#lowerBoundary = 144;
|
|
57
|
+
if (byte === 244) this.#upperBoundary = 143;
|
|
58
|
+
this.#start(3, byte & 7);
|
|
59
|
+
} else codePoints.push(this.#error());
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (byte < this.#lowerBoundary || byte > this.#upperBoundary) {
|
|
63
|
+
this.#reset();
|
|
64
|
+
codePoints.push(this.#error());
|
|
65
|
+
i--;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
this.#lowerBoundary = 128;
|
|
69
|
+
this.#upperBoundary = 191;
|
|
70
|
+
this.#codePoint = this.#codePoint << 6 | byte & 63;
|
|
71
|
+
if (++this.#bytesSeen === this.#bytesNeeded) {
|
|
72
|
+
codePoints.push(this.#codePoint);
|
|
73
|
+
this.#reset();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!options.stream && this.#bytesNeeded > 0) {
|
|
77
|
+
this.#reset();
|
|
78
|
+
codePoints.push(this.#error());
|
|
79
|
+
}
|
|
80
|
+
if (this.#atStart && codePoints.length > 0) {
|
|
81
|
+
this.#atStart = false;
|
|
82
|
+
if (!this.ignoreBOM && codePoints[0] === 65279) codePoints.shift();
|
|
83
|
+
}
|
|
84
|
+
if (!options.stream) this.#atStart = true;
|
|
85
|
+
return codePointsToString(codePoints);
|
|
86
|
+
}
|
|
87
|
+
#start(bytesNeeded, codePoint) {
|
|
88
|
+
this.#bytesNeeded = bytesNeeded;
|
|
89
|
+
this.#codePoint = codePoint;
|
|
90
|
+
}
|
|
91
|
+
#reset() {
|
|
92
|
+
this.#codePoint = 0;
|
|
93
|
+
this.#bytesNeeded = 0;
|
|
94
|
+
this.#bytesSeen = 0;
|
|
95
|
+
this.#lowerBoundary = 128;
|
|
96
|
+
this.#upperBoundary = 191;
|
|
97
|
+
}
|
|
98
|
+
#error() {
|
|
99
|
+
if (this.fatal) {
|
|
100
|
+
this.#atStart = true;
|
|
101
|
+
throw new TypeError("The encoded data was not valid utf-8.");
|
|
102
|
+
}
|
|
103
|
+
return REPLACEMENT;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function codePointsToString(codePoints) {
|
|
107
|
+
let out = "";
|
|
108
|
+
for (let i = 0; i < codePoints.length; i += 32768) out += String.fromCodePoint(...codePoints.slice(i, i + 32768));
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
Object.defineProperty(exports, 'Utf8TextDecoder', {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () {
|
|
116
|
+
return Utf8TextDecoder;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(exports, 'Utf8TextEncoder', {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function () {
|
|
122
|
+
return Utf8TextEncoder;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=utf8-Cf3Ssy33.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-Cf3Ssy33.cjs","names":["#bytesNeeded","#start","#lowerBoundary","#upperBoundary","#error","#reset","#codePoint","#bytesSeen","#atStart"],"sources":["../src/polyfills/utf8.ts"],"sourcesContent":["/**\n * UTF-8 `TextEncoder` and `TextDecoder`, for runtimes that have neither.\n *\n * CopilotKit only reads and writes UTF-8, so these classes support only that\n * encoding. The decoder follows the WHATWG UTF-8 decode algorithm, so its\n * output, including U+FFFD for invalid bytes and `{ stream: true }` chunks,\n * matches the built-in `TextDecoder`.\n */\n\nconst REPLACEMENT = 0xfffd;\n\nexport class Utf8TextEncoder {\n readonly encoding = \"utf-8\";\n\n encode(input = \"\"): Uint8Array {\n const bytes: number[] = [];\n for (const char of input) {\n let codePoint = char.codePointAt(0)!;\n // A lone surrogate is not a Unicode scalar value.\n if (codePoint >= 0xd800 && codePoint <= 0xdfff) codePoint = REPLACEMENT;\n if (codePoint < 0x80) bytes.push(codePoint);\n else if (codePoint < 0x800)\n bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));\n else if (codePoint < 0x10000)\n bytes.push(\n 0xe0 | (codePoint >> 12),\n 0x80 | ((codePoint >> 6) & 0x3f),\n 0x80 | (codePoint & 0x3f),\n );\n else\n bytes.push(\n 0xf0 | (codePoint >> 18),\n 0x80 | ((codePoint >> 12) & 0x3f),\n 0x80 | ((codePoint >> 6) & 0x3f),\n 0x80 | (codePoint & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n}\n\nexport class Utf8TextDecoder {\n readonly encoding = \"utf-8\";\n readonly fatal: boolean;\n readonly ignoreBOM: boolean;\n\n #codePoint = 0;\n #bytesNeeded = 0;\n #bytesSeen = 0;\n #lowerBoundary = 0x80;\n #upperBoundary = 0xbf;\n #atStart = true;\n\n constructor(\n label = \"utf-8\",\n options: { fatal?: boolean; ignoreBOM?: boolean } = {},\n ) {\n const normalized = String(label).trim().toLowerCase();\n if (normalized !== \"utf-8\" && normalized !== \"utf8\") {\n throw new RangeError(`The \"${label}\" encoding is not supported.`);\n }\n this.fatal = options.fatal ?? false;\n this.ignoreBOM = options.ignoreBOM ?? false;\n }\n\n decode(\n input?: ArrayBuffer | ArrayBufferView,\n options: { stream?: boolean } = {},\n ): string {\n const bytes =\n input === undefined\n ? new Uint8Array(0)\n : ArrayBuffer.isView(input)\n ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)\n : new Uint8Array(input);\n const codePoints: number[] = [];\n\n for (let i = 0; i < bytes.length; i++) {\n const byte = bytes[i];\n if (this.#bytesNeeded === 0) {\n if (byte <= 0x7f) codePoints.push(byte);\n else if (byte >= 0xc2 && byte <= 0xdf) this.#start(1, byte & 0x1f);\n else if (byte >= 0xe0 && byte <= 0xef) {\n if (byte === 0xe0) this.#lowerBoundary = 0xa0;\n if (byte === 0xed) this.#upperBoundary = 0x9f;\n this.#start(2, byte & 0x0f);\n } else if (byte >= 0xf0 && byte <= 0xf4) {\n if (byte === 0xf0) this.#lowerBoundary = 0x90;\n if (byte === 0xf4) this.#upperBoundary = 0x8f;\n this.#start(3, byte & 0x07);\n } else codePoints.push(this.#error());\n continue;\n }\n if (byte < this.#lowerBoundary || byte > this.#upperBoundary) {\n // The sequence ends early. Read this byte again as a new sequence.\n this.#reset();\n codePoints.push(this.#error());\n i--;\n continue;\n }\n this.#lowerBoundary = 0x80;\n this.#upperBoundary = 0xbf;\n this.#codePoint = (this.#codePoint << 6) | (byte & 0x3f);\n if (++this.#bytesSeen === this.#bytesNeeded) {\n codePoints.push(this.#codePoint);\n this.#reset();\n }\n }\n\n if (!options.stream && this.#bytesNeeded > 0) {\n this.#reset();\n codePoints.push(this.#error());\n }\n if (this.#atStart && codePoints.length > 0) {\n this.#atStart = false;\n if (!this.ignoreBOM && codePoints[0] === 0xfeff) codePoints.shift();\n }\n if (!options.stream) this.#atStart = true;\n return codePointsToString(codePoints);\n }\n\n #start(bytesNeeded: number, codePoint: number): void {\n this.#bytesNeeded = bytesNeeded;\n this.#codePoint = codePoint;\n }\n\n #reset(): void {\n this.#codePoint = 0;\n this.#bytesNeeded = 0;\n this.#bytesSeen = 0;\n this.#lowerBoundary = 0x80;\n this.#upperBoundary = 0xbf;\n }\n\n #error(): number {\n if (this.fatal) {\n this.#atStart = true;\n throw new TypeError(\"The encoded data was not valid utf-8.\");\n }\n return REPLACEMENT;\n }\n}\n\nfunction codePointsToString(codePoints: number[]): string {\n let out = \"\";\n // Stay under the engine's limit on function arguments.\n for (let i = 0; i < codePoints.length; i += 0x8000) {\n out += String.fromCodePoint(...codePoints.slice(i, i + 0x8000));\n }\n return out;\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/react-native",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://github.com/CopilotKit/CopilotKit",
|
|
14
14
|
"license": "MIT",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
20
|
"url": "https://github.com/CopilotKit/CopilotKit.git"
|
|
@@ -74,11 +77,10 @@
|
|
|
74
77
|
},
|
|
75
78
|
"dependencies": {
|
|
76
79
|
"@ag-ui/client": "1.0.2",
|
|
77
|
-
"@copilotkit/core": "2.0.0-rc.
|
|
78
|
-
"@copilotkit/markdown
|
|
79
|
-
"@copilotkit/react-core": "2.0.0-rc.
|
|
80
|
-
"@copilotkit/shared": "2.0.0-rc.
|
|
81
|
-
"text-encoding": "^0.7.0",
|
|
80
|
+
"@copilotkit/core": "2.0.0-rc.20",
|
|
81
|
+
"@copilotkit/markdown": "2.0.0-rc.20",
|
|
82
|
+
"@copilotkit/react-core": "2.0.0-rc.20",
|
|
83
|
+
"@copilotkit/shared": "2.0.0-rc.20",
|
|
82
84
|
"web-streams-polyfill": "^4.2.0"
|
|
83
85
|
},
|
|
84
86
|
"devDependencies": {
|
|
@@ -90,17 +92,15 @@
|
|
|
90
92
|
"react-dom": "^19.1.0",
|
|
91
93
|
"tsdown": "^0.20.3",
|
|
92
94
|
"typescript": "^5.8.3",
|
|
93
|
-
"vitest": "^3.2.4"
|
|
95
|
+
"vitest": "^3.2.4",
|
|
96
|
+
"zod": "^4.2.0"
|
|
94
97
|
},
|
|
95
98
|
"peerDependencies": {
|
|
96
99
|
"@gorhom/bottom-sheet": "^5.0.0",
|
|
97
100
|
"expo-document-picker": ">=12.0.0",
|
|
98
101
|
"expo-file-system": ">=17.0.0",
|
|
99
102
|
"react": "^18 || ^19",
|
|
100
|
-
"react-native": ">=0.70"
|
|
101
|
-
"react-native-gesture-handler": ">=2.0.0",
|
|
102
|
-
"react-native-reanimated": ">=3.0.0",
|
|
103
|
-
"zod": ">=3.0.0"
|
|
103
|
+
"react-native": ">=0.70"
|
|
104
104
|
},
|
|
105
105
|
"peerDependenciesMeta": {
|
|
106
106
|
"@gorhom/bottom-sheet": {
|
|
@@ -111,15 +111,6 @@
|
|
|
111
111
|
},
|
|
112
112
|
"expo-file-system": {
|
|
113
113
|
"optional": true
|
|
114
|
-
},
|
|
115
|
-
"react-native-gesture-handler": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
|
-
"react-native-reanimated": {
|
|
119
|
-
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"zod": {
|
|
122
|
-
"optional": true
|
|
123
114
|
}
|
|
124
115
|
},
|
|
125
116
|
"scripts": {
|
|
@@ -17,11 +17,9 @@
|
|
|
17
17
|
// natively, so asserting they are merely "defined" afterwards would pass on
|
|
18
18
|
// an empty barrel; clearing them first is what makes the check honest. It
|
|
19
19
|
// runs in a child process so the probe cannot poison this one.
|
|
20
|
-
// - ESM is checked structurally
|
|
21
|
-
// polyfill
|
|
22
|
-
//
|
|
23
|
-
// Node ESM refuses it. Asserting the five imports survive the bundler is
|
|
24
|
-
// the part this file exists to protect.
|
|
20
|
+
// - ESM is checked structurally: the CJS run already proves that each
|
|
21
|
+
// polyfill installs its globals. Asserting the five imports survive the
|
|
22
|
+
// bundler is the part this file exists to protect.
|
|
25
23
|
//
|
|
26
24
|
// Invoked from package.json `build`, so a barrel that installs nothing fails
|
|
27
25
|
// the build rather than reaching npm.
|
|
@@ -73,7 +71,7 @@ export function assertBuilt(distDir) {
|
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
73
|
* Which polyfill modules the ESM barrel no longer imports. Pure; the ESM barrel
|
|
76
|
-
* is read as text rather than executed (see the header note
|
|
74
|
+
* is read as text rather than executed (see the header note).
|
|
77
75
|
*/
|
|
78
76
|
export function missingEsmImports(esmSource) {
|
|
79
77
|
return GROUPS.filter(
|
package/src/CopilotChat.tsx
CHANGED
|
@@ -6,7 +6,11 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
} from "react";
|
|
8
8
|
import type { ReactNode } from "react";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
CopilotChatConfigurationProvider,
|
|
11
|
+
useAgent,
|
|
12
|
+
useCopilotChatConfiguration,
|
|
13
|
+
} from "@copilotkit/react-core/headless";
|
|
10
14
|
import { useCopilotKit } from "@copilotkit/react-core/context";
|
|
11
15
|
import { DEFAULT_AGENT_ID, randomUUID } from "@copilotkit/shared";
|
|
12
16
|
import type { InputContent } from "@copilotkit/shared";
|
|
@@ -67,7 +71,8 @@ export interface CopilotChatBaseProps {
|
|
|
67
71
|
* The agent ID to use for this chat session.
|
|
68
72
|
* Matches the web SDK's CopilotChat `agentId` prop.
|
|
69
73
|
*
|
|
70
|
-
* Resolution order: `agentId` > `agentName` >
|
|
74
|
+
* Resolution order: `agentId` > `agentName` > the agent of the chat (or
|
|
75
|
+
* `CopilotChatConfigurationProvider`) around this one > `"default"`
|
|
71
76
|
*/
|
|
72
77
|
agentId?: string;
|
|
73
78
|
|
|
@@ -85,8 +90,8 @@ export interface CopilotChatBaseProps {
|
|
|
85
90
|
|
|
86
91
|
/**
|
|
87
92
|
* Error handler scoped to this chat's agent. Fires in addition to the
|
|
88
|
-
* provider-level onError (does not suppress it). Receives
|
|
89
|
-
*
|
|
93
|
+
* provider-level onError (does not suppress it). Receives errors whose
|
|
94
|
+
* context.agentId matches this chat's agent, and errors with no agentId.
|
|
90
95
|
*/
|
|
91
96
|
onError?: (event: {
|
|
92
97
|
error: Error;
|
|
@@ -130,6 +135,16 @@ export interface CopilotChatProps extends CopilotChatBaseProps {
|
|
|
130
135
|
*
|
|
131
136
|
* Children can access chat state via `useCopilotChatContext()`.
|
|
132
137
|
*
|
|
138
|
+
* Hooks inside the chat, such as `useAgent` and `useInterrupt`, use this
|
|
139
|
+
* chat's agent when they do not pass an `agentId`. When the chat has a
|
|
140
|
+
* `threadId`, `useAgent` inside the chat sets that thread on each agent it
|
|
141
|
+
* returns, also on an agent that the hook names with its own `agentId`. Only
|
|
142
|
+
* `useAgent({ agentId, runtimeAgentId, threadId })` keeps a different thread.
|
|
143
|
+
*
|
|
144
|
+
* A chat inside another chat uses the outer chat's agent when it has no
|
|
145
|
+
* `agentId`. When the outer chat has a `threadId` and the inner chat does not,
|
|
146
|
+
* the inner chat uses the outer thread. The web `CopilotChat` does the same.
|
|
147
|
+
*
|
|
133
148
|
* ```tsx
|
|
134
149
|
* import { CopilotChat, useCopilotChatContext } from "@copilotkit/react-native";
|
|
135
150
|
*
|
|
@@ -153,7 +168,11 @@ export function CopilotChat({
|
|
|
153
168
|
children,
|
|
154
169
|
..._rest
|
|
155
170
|
}: CopilotChatProps) {
|
|
156
|
-
|
|
171
|
+
// Same precedence as the web CopilotChat: a chat that names no agent takes
|
|
172
|
+
// the agent of the chat configuration around it before "default".
|
|
173
|
+
const chatConfig = useCopilotChatConfiguration();
|
|
174
|
+
const resolvedAgentId =
|
|
175
|
+
agentId ?? agentName ?? chatConfig?.agentId ?? DEFAULT_AGENT_ID;
|
|
157
176
|
|
|
158
177
|
// Deprecation warning (dev only, fires once per mount)
|
|
159
178
|
const warnedRef = useRef(false);
|
|
@@ -198,7 +217,7 @@ export function CopilotChat({
|
|
|
198
217
|
event.context?.agentId === resolvedAgentId ||
|
|
199
218
|
!event.context?.agentId
|
|
200
219
|
) {
|
|
201
|
-
onErrorRef.current?.({
|
|
220
|
+
void onErrorRef.current?.({
|
|
202
221
|
error: event.error,
|
|
203
222
|
code: event.code,
|
|
204
223
|
context: event.context,
|
|
@@ -287,9 +306,17 @@ export function CopilotChat({
|
|
|
287
306
|
submitMessage,
|
|
288
307
|
};
|
|
289
308
|
|
|
309
|
+
// Publish this chat's agent and thread to the subtree, as the web
|
|
310
|
+
// CopilotChat does. Hooks inside it that name no agent use this chat's
|
|
311
|
+
// agent, which is the outer chat's agent when this chat names none.
|
|
290
312
|
return (
|
|
291
|
-
<
|
|
292
|
-
{
|
|
293
|
-
|
|
313
|
+
<CopilotChatConfigurationProvider
|
|
314
|
+
agentId={resolvedAgentId}
|
|
315
|
+
threadId={threadId}
|
|
316
|
+
>
|
|
317
|
+
<CopilotChatCtx.Provider value={contextValue}>
|
|
318
|
+
{children}
|
|
319
|
+
</CopilotChatCtx.Provider>
|
|
320
|
+
</CopilotChatConfigurationProvider>
|
|
294
321
|
);
|
|
295
322
|
}
|
|
@@ -71,7 +71,8 @@ export interface CopilotKitNativeProviderProps {
|
|
|
71
71
|
}) => void | Promise<void>;
|
|
72
72
|
/**
|
|
73
73
|
* Enable debug logging for the client-side event pipeline.
|
|
74
|
-
*
|
|
74
|
+
* `true` logs event and lifecycle summaries. Pass `{ verbose: true }` for
|
|
75
|
+
* full event payloads.
|
|
75
76
|
*/
|
|
76
77
|
debug?: DebugConfig;
|
|
77
78
|
/**
|
|
@@ -243,7 +244,7 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
243
244
|
},
|
|
244
245
|
onError: (event) => {
|
|
245
246
|
if (onErrorRef.current) {
|
|
246
|
-
onErrorRef.current(event);
|
|
247
|
+
void onErrorRef.current(event);
|
|
247
248
|
} else {
|
|
248
249
|
console.error(
|
|
249
250
|
`[CopilotKit] Error (${event.code}):`,
|
package/src/CopilotPopup.tsx
CHANGED
|
@@ -78,8 +78,8 @@ export interface CopilotPopupProps {
|
|
|
78
78
|
attachments?: NativeAttachmentsConfig;
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
81
|
+
* Your chat UI, rendered inside the popup card below the header. The inner
|
|
82
|
+
* CopilotChat is headless and draws no messages or input of its own.
|
|
83
83
|
*/
|
|
84
84
|
children?: ReactNode;
|
|
85
85
|
|
package/src/CopilotSidebar.tsx
CHANGED
|
@@ -70,7 +70,10 @@ export interface CopilotSidebarProps extends Omit<
|
|
|
70
70
|
/** Custom style applied to the drawer container. */
|
|
71
71
|
style?: ViewStyle;
|
|
72
72
|
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Your chat UI, rendered inside the drawer below the header. The inner
|
|
75
|
+
* CopilotChat is headless and draws no messages or input of its own.
|
|
76
|
+
*/
|
|
74
77
|
children?: ReactNode;
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* would stub the very thing under test. Driving a real core exercises the
|
|
10
10
|
* production path end-to-end.
|
|
11
11
|
*
|
|
12
|
-
* The core and its
|
|
12
|
+
* The core and its agents are created ONCE (via refs) and kept
|
|
13
13
|
* stable across re-renders. That stability is load-bearing: `useRenderTool`
|
|
14
14
|
* registers its renderer into core and deliberately does NOT remove it on
|
|
15
15
|
* unmount, so a renderer registered on one render must survive a later
|
|
@@ -38,7 +38,7 @@ import type { CopilotKitContextValue } from "@copilotkit/react-core/context";
|
|
|
38
38
|
* bundler cannot resolve a bare `rxjs` import. A throw-only body is assignable
|
|
39
39
|
* to any declared return type, so no Observable value is constructed.
|
|
40
40
|
*/
|
|
41
|
-
class SeededAgent extends AbstractAgent {
|
|
41
|
+
export class SeededAgent extends AbstractAgent {
|
|
42
42
|
run(): ReturnType<AbstractAgent["run"]> {
|
|
43
43
|
throw new Error("SeededAgent.run() is not used in tests");
|
|
44
44
|
}
|
|
@@ -83,6 +83,11 @@ export interface TestCopilotKitProps {
|
|
|
83
83
|
* instance, and therefore the registered renderers, must stay stable).
|
|
84
84
|
*/
|
|
85
85
|
agent?: AbstractAgent;
|
|
86
|
+
/**
|
|
87
|
+
* More agents to register next to "default", keyed by agent id, for tests
|
|
88
|
+
* that pick a non-default agent. Captured on first render like `agent`.
|
|
89
|
+
*/
|
|
90
|
+
agents?: Record<string, AbstractAgent>;
|
|
86
91
|
children: React.ReactNode;
|
|
87
92
|
}
|
|
88
93
|
|
|
@@ -91,6 +96,7 @@ export function TestCopilotKit({
|
|
|
91
96
|
executingToolCallIds = EMPTY_SET,
|
|
92
97
|
agentRef: publishAgentRef,
|
|
93
98
|
agent,
|
|
99
|
+
agents,
|
|
94
100
|
children,
|
|
95
101
|
}: TestCopilotKitProps) {
|
|
96
102
|
const agentRef = useRef<AbstractAgent | null>(null);
|
|
@@ -102,7 +108,7 @@ export function TestCopilotKit({
|
|
|
102
108
|
const copilotkitRef = useRef<CopilotKitCoreReact | null>(null);
|
|
103
109
|
if (copilotkitRef.current === null) {
|
|
104
110
|
copilotkitRef.current = new CopilotKitCoreReact({
|
|
105
|
-
agents__unsafe_dev_only: { default: agentRef.current },
|
|
111
|
+
agents__unsafe_dev_only: { ...agents, default: agentRef.current },
|
|
106
112
|
});
|
|
107
113
|
}
|
|
108
114
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks inside the headless `<CopilotChat agentId>` must use that chat's agent,
|
|
3
|
+
* as they do inside the web CopilotChat. Runs on a REAL `CopilotKitCoreReact`
|
|
4
|
+
* (via `TestCopilotKit`) and the real react-core hooks: mocking
|
|
5
|
+
* `@copilotkit/react-core/headless` (as the sibling chat tests do) would
|
|
6
|
+
* stub the chat configuration under test.
|
|
7
|
+
*/
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { render } from "@testing-library/react";
|
|
10
|
+
import { describe, it, expect } from "vitest";
|
|
11
|
+
import type { AbstractAgent } from "@ag-ui/client";
|
|
12
|
+
import {
|
|
13
|
+
useAgent,
|
|
14
|
+
useCopilotChatConfiguration,
|
|
15
|
+
} from "@copilotkit/react-core/headless";
|
|
16
|
+
import { CopilotChat, useCopilotChatContext } from "../CopilotChat";
|
|
17
|
+
import { SeededAgent, TestCopilotKit } from "../__mocks__/test-copilotkit";
|
|
18
|
+
|
|
19
|
+
function renderInChat(chat: React.ReactElement) {
|
|
20
|
+
const agents = { x: new SeededAgent() };
|
|
21
|
+
render(
|
|
22
|
+
<TestCopilotKit messages={[]} agents={agents}>
|
|
23
|
+
{chat}
|
|
24
|
+
</TestCopilotKit>,
|
|
25
|
+
);
|
|
26
|
+
return agents;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("headless CopilotChat chat configuration", () => {
|
|
30
|
+
it("gives hooks inside <CopilotChat agentId> that agent", () => {
|
|
31
|
+
let seen: AbstractAgent | undefined;
|
|
32
|
+
function Probe() {
|
|
33
|
+
seen = useAgent().agent;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const agents = renderInChat(
|
|
38
|
+
<CopilotChat agentId="x">
|
|
39
|
+
<Probe />
|
|
40
|
+
</CopilotChat>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(seen).toBe(agents.x);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("gives hooks inside <CopilotChat threadId> that thread", () => {
|
|
47
|
+
let seenThreadId: string | undefined;
|
|
48
|
+
function Probe() {
|
|
49
|
+
seenThreadId = useCopilotChatConfiguration()?.threadId;
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
renderInChat(
|
|
54
|
+
<CopilotChat agentId="x" threadId="thread-1">
|
|
55
|
+
<Probe />
|
|
56
|
+
</CopilotChat>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(seenThreadId).toBe("thread-1");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("gives a <CopilotChat> without agentId the agent of the chat around it", () => {
|
|
63
|
+
let seenByChat: AbstractAgent | undefined;
|
|
64
|
+
let seenByHook: AbstractAgent | undefined;
|
|
65
|
+
function Probe() {
|
|
66
|
+
seenByChat = useCopilotChatContext().agent;
|
|
67
|
+
seenByHook = useAgent().agent;
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const agents = renderInChat(
|
|
72
|
+
<CopilotChat agentId="x">
|
|
73
|
+
<CopilotChat>
|
|
74
|
+
<Probe />
|
|
75
|
+
</CopilotChat>
|
|
76
|
+
</CopilotChat>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(seenByChat).toBe(agents.x);
|
|
80
|
+
expect(seenByHook).toBe(agents.x);
|
|
81
|
+
});
|
|
82
|
+
});
|