@copilotkit/react-ui 0.22.0-function-calling-fixes.1 → 0.22.0-function-calling-fixes.2
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/.turbo/turbo-build.log +133 -129
- package/CHANGELOG.md +12 -0
- package/dist/components/chat/Button.mjs +30 -6
- package/dist/components/chat/Button.mjs.map +1 -1
- package/dist/components/chat/Chat.mjs +1198 -16
- package/dist/components/chat/Chat.mjs.map +1 -1
- package/dist/components/chat/ChatContext.mjs +217 -7
- package/dist/components/chat/ChatContext.mjs.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +483 -8
- package/dist/components/chat/CodeBlock.mjs.map +1 -1
- package/dist/components/chat/Header.mjs +23 -6
- package/dist/components/chat/Header.mjs.map +1 -1
- package/dist/components/chat/Icons.mjs +218 -14
- package/dist/components/chat/Icons.mjs.map +1 -1
- package/dist/components/chat/Input.mjs +116 -7
- package/dist/components/chat/Input.mjs.map +1 -1
- package/dist/components/chat/Markdown.mjs +547 -7
- package/dist/components/chat/Markdown.mjs.map +1 -1
- package/dist/components/chat/Messages.mjs +678 -9
- package/dist/components/chat/Messages.mjs.map +1 -1
- package/dist/components/chat/Popup.mjs +1207 -17
- package/dist/components/chat/Popup.mjs.map +1 -1
- package/dist/components/chat/Response.mjs +23 -6
- package/dist/components/chat/Response.mjs.map +1 -1
- package/dist/components/chat/Sidebar.mjs +1218 -17
- package/dist/components/chat/Sidebar.mjs.map +1 -1
- package/dist/components/chat/Textarea.mjs +48 -4
- package/dist/components/chat/Textarea.mjs.map +1 -1
- package/dist/components/chat/Window.mjs +105 -4
- package/dist/components/chat/Window.mjs.map +1 -1
- package/dist/components/chat/index.mjs +1225 -24
- package/dist/components/chat/index.mjs.map +1 -1
- package/dist/components/chat/props.mjs +0 -1
- package/dist/components/index.mjs +1225 -25
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/index.mjs +0 -1
- package/dist/hooks/index.mjs +0 -1
- package/dist/hooks/use-copy-to-clipboard.mjs +21 -4
- package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -1
- package/dist/index.mjs +1225 -28
- package/dist/index.mjs.map +1 -1
- package/dist/lib/utils.mjs +20 -3
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/types/index.mjs +0 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,1229 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/components/chat/Chat.tsx
|
|
55
|
+
import React7, { useEffect as useEffect5 } from "react";
|
|
56
|
+
|
|
57
|
+
// src/components/chat/ChatContext.tsx
|
|
58
|
+
import React, { useMemo } from "react";
|
|
59
|
+
|
|
60
|
+
// src/components/chat/Icons.tsx
|
|
61
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
62
|
+
var OpenIcon = /* @__PURE__ */ jsx(
|
|
63
|
+
"svg",
|
|
64
|
+
{
|
|
65
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
66
|
+
viewBox: "0 0 24 24",
|
|
67
|
+
fill: "currentColor",
|
|
68
|
+
width: "24",
|
|
69
|
+
height: "24",
|
|
70
|
+
children: /* @__PURE__ */ jsx("g", { transform: "translate(24, 0) scale(-1, 1)", children: /* @__PURE__ */ jsx(
|
|
71
|
+
"path",
|
|
72
|
+
{
|
|
73
|
+
fillRule: "evenodd",
|
|
74
|
+
d: "M5.337 21.718a6.707 6.707 0 01-.533-.074.75.75 0 01-.44-1.223 3.73 3.73 0 00.814-1.686c.023-.115-.022-.317-.254-.543C3.274 16.587 2.25 14.41 2.25 12c0-5.03 4.428-9 9.75-9s9.75 3.97 9.75 9c0 5.03-4.428 9-9.75 9-.833 0-1.643-.097-2.417-.279a6.721 6.721 0 01-4.246.997z",
|
|
75
|
+
clipRule: "evenodd"
|
|
76
|
+
}
|
|
77
|
+
) })
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
var CloseIcon = /* @__PURE__ */ jsx(
|
|
81
|
+
"svg",
|
|
82
|
+
{
|
|
83
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
84
|
+
fill: "none",
|
|
85
|
+
viewBox: "0 0 24 24",
|
|
86
|
+
strokeWidth: "1.5",
|
|
87
|
+
stroke: "currentColor",
|
|
88
|
+
width: "24",
|
|
89
|
+
height: "24",
|
|
90
|
+
children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" })
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
var HeaderCloseIcon = /* @__PURE__ */ jsx(
|
|
94
|
+
"svg",
|
|
95
|
+
{
|
|
96
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
97
|
+
fill: "none",
|
|
98
|
+
viewBox: "0 0 24 24",
|
|
99
|
+
strokeWidth: "1.5",
|
|
100
|
+
stroke: "currentColor",
|
|
101
|
+
width: "24",
|
|
102
|
+
height: "24",
|
|
103
|
+
children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
var SendIcon = /* @__PURE__ */ jsx(
|
|
107
|
+
"svg",
|
|
108
|
+
{
|
|
109
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
110
|
+
fill: "none",
|
|
111
|
+
viewBox: "0 0 24 24",
|
|
112
|
+
strokeWidth: 1.5,
|
|
113
|
+
stroke: "currentColor",
|
|
114
|
+
width: "24",
|
|
115
|
+
height: "24",
|
|
116
|
+
children: /* @__PURE__ */ jsx(
|
|
117
|
+
"path",
|
|
118
|
+
{
|
|
119
|
+
strokeLinecap: "round",
|
|
120
|
+
strokeLinejoin: "round",
|
|
121
|
+
d: "M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
var SpinnerIcon = /* @__PURE__ */ jsxs(
|
|
127
|
+
"svg",
|
|
128
|
+
{
|
|
129
|
+
style: {
|
|
130
|
+
animation: "copilotKitSpinAnimation 1s linear infinite",
|
|
131
|
+
color: "rgb(107 114 128)"
|
|
132
|
+
},
|
|
133
|
+
width: "24",
|
|
134
|
+
height: "24",
|
|
135
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
136
|
+
fill: "none",
|
|
137
|
+
viewBox: "0 0 24 24",
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
"circle",
|
|
141
|
+
{
|
|
142
|
+
style: { opacity: 0.25 },
|
|
143
|
+
cx: "12",
|
|
144
|
+
cy: "12",
|
|
145
|
+
r: "10",
|
|
146
|
+
stroke: "currentColor",
|
|
147
|
+
strokeWidth: "4"
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
/* @__PURE__ */ jsx(
|
|
151
|
+
"path",
|
|
152
|
+
{
|
|
153
|
+
style: { opacity: 0.75 },
|
|
154
|
+
fill: "currentColor",
|
|
155
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
var ActivityIcon = /* @__PURE__ */ jsxs(
|
|
162
|
+
"svg",
|
|
163
|
+
{
|
|
164
|
+
style: {
|
|
165
|
+
display: "inline-block",
|
|
166
|
+
marginLeft: "0.25rem",
|
|
167
|
+
marginRight: "0.25rem"
|
|
168
|
+
},
|
|
169
|
+
height: "24",
|
|
170
|
+
width: "24",
|
|
171
|
+
viewBox: "0 0 27 27",
|
|
172
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
173
|
+
fill: "currentColor",
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ jsx("circle", { className: "copilotKitActivityDot1", cx: "4", cy: "12", r: "3" }),
|
|
176
|
+
/* @__PURE__ */ jsx("circle", { className: "copilotKitActivityDot1 copilotKitActivityDot2", cx: "12", cy: "12", r: "3" }),
|
|
177
|
+
/* @__PURE__ */ jsx("circle", { className: "copilotKitActivityDot1 copilotKitActivityDot3", cx: "20", cy: "12", r: "3" })
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
function CheckIcon(_a) {
|
|
182
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
"svg",
|
|
185
|
+
__spreadProps(__spreadValues({
|
|
186
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
187
|
+
viewBox: "0 0 256 256",
|
|
188
|
+
fill: "currentColor",
|
|
189
|
+
style: { height: "1rem", width: "1rem" },
|
|
190
|
+
className
|
|
191
|
+
}, props), {
|
|
192
|
+
children: /* @__PURE__ */ jsx("path", { d: "m229.66 77.66-128 128a8 8 0 0 1-11.32 0l-56-56a8 8 0 0 1 11.32-11.32L96 188.69 218.34 66.34a8 8 0 0 1 11.32 11.32Z" })
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function DownloadIcon(_a) {
|
|
197
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
198
|
+
return /* @__PURE__ */ jsx(
|
|
199
|
+
"svg",
|
|
200
|
+
__spreadProps(__spreadValues({
|
|
201
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
202
|
+
viewBox: "0 0 256 256",
|
|
203
|
+
fill: "currentColor",
|
|
204
|
+
style: { height: "1rem", width: "1rem" },
|
|
205
|
+
className
|
|
206
|
+
}, props), {
|
|
207
|
+
children: /* @__PURE__ */ jsx("path", { d: "M224 152v56a16 16 0 0 1-16 16H48a16 16 0 0 1-16-16v-56a8 8 0 0 1 16 0v56h160v-56a8 8 0 0 1 16 0Zm-101.66 5.66a8 8 0 0 0 11.32 0l40-40a8 8 0 0 0-11.32-11.32L136 132.69V40a8 8 0 0 0-16 0v92.69l-26.34-26.35a8 8 0 0 0-11.32 11.32Z" })
|
|
208
|
+
})
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
function CopyIcon(_a) {
|
|
212
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
213
|
+
return /* @__PURE__ */ jsx(
|
|
214
|
+
"svg",
|
|
215
|
+
__spreadProps(__spreadValues({
|
|
216
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
217
|
+
viewBox: "0 0 256 256",
|
|
218
|
+
fill: "currentColor",
|
|
219
|
+
style: { height: "1rem", width: "1rem" },
|
|
220
|
+
className
|
|
221
|
+
}, props), {
|
|
222
|
+
children: /* @__PURE__ */ jsx("path", { d: "M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8Zm-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z" })
|
|
223
|
+
})
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
var StopIcon = /* @__PURE__ */ jsx(
|
|
227
|
+
"svg",
|
|
228
|
+
{
|
|
229
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
230
|
+
viewBox: "0 0 256 256",
|
|
231
|
+
fill: "currentColor",
|
|
232
|
+
style: { height: "1rem", width: "1rem" },
|
|
233
|
+
children: /* @__PURE__ */ jsx("path", { d: "M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm0 192a88 88 0 1 1 88-88 88.1 88.1 0 0 1-88 88Zm24-120h-48a8 8 0 0 0-8 8v48a8 8 0 0 0 8 8h48a8 8 0 0 0 8-8v-48a8 8 0 0 0-8-8Zm-8 48h-32v-32h32Z" })
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
var RegenerateIcon = /* @__PURE__ */ jsx(
|
|
237
|
+
"svg",
|
|
238
|
+
{
|
|
239
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
240
|
+
viewBox: "0 0 256 256",
|
|
241
|
+
fill: "currentColor",
|
|
242
|
+
style: { height: "1rem", width: "1rem" },
|
|
243
|
+
children: /* @__PURE__ */ jsx("path", { d: "M197.67 186.37a8 8 0 0 1 0 11.29C196.58 198.73 170.82 224 128 224c-37.39 0-64.53-22.4-80-39.85V208a8 8 0 0 1-16 0v-48a8 8 0 0 1 8-8h48a8 8 0 0 1 0 16H55.44C67.76 183.35 93 208 128 208c36 0 58.14-21.46 58.36-21.68a8 8 0 0 1 11.31.05ZM216 40a8 8 0 0 0-8 8v23.85C192.53 54.4 165.39 32 128 32c-42.82 0-68.58 25.27-69.66 26.34a8 8 0 0 0 11.3 11.34C69.86 69.46 92 48 128 48c35 0 60.24 24.65 72.56 40H168a8 8 0 0 0 0 16h48a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8Z" })
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// src/components/chat/ChatContext.tsx
|
|
248
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
249
|
+
var ChatContext = React.createContext(void 0);
|
|
250
|
+
function useChatContext() {
|
|
251
|
+
const context = React.useContext(ChatContext);
|
|
252
|
+
if (context === void 0) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
"Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?"
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
return context;
|
|
258
|
+
}
|
|
259
|
+
var ChatContextProvider = ({
|
|
260
|
+
// temperature,
|
|
261
|
+
// instructions,
|
|
262
|
+
// maxFeedback,
|
|
263
|
+
labels,
|
|
264
|
+
icons,
|
|
265
|
+
children,
|
|
266
|
+
open,
|
|
267
|
+
setOpen
|
|
268
|
+
}) => {
|
|
269
|
+
const context = useMemo(
|
|
270
|
+
() => ({
|
|
271
|
+
labels: __spreadValues(__spreadValues({}, {
|
|
272
|
+
initial: "",
|
|
273
|
+
title: "CopilotKit",
|
|
274
|
+
placeholder: "Type a message...",
|
|
275
|
+
thinking: "Thinking...",
|
|
276
|
+
error: "\u274C An error occurred. Please try again.",
|
|
277
|
+
stopGenerating: "Stop generating",
|
|
278
|
+
regenerateResponse: "Regenerate response"
|
|
279
|
+
}), labels),
|
|
280
|
+
icons: __spreadProps(__spreadValues({}, {
|
|
281
|
+
openIcon: OpenIcon,
|
|
282
|
+
closeIcon: CloseIcon,
|
|
283
|
+
headerCloseIcon: HeaderCloseIcon,
|
|
284
|
+
sendIcon: SendIcon,
|
|
285
|
+
activityIcon: ActivityIcon,
|
|
286
|
+
spinnerIcon: SpinnerIcon,
|
|
287
|
+
stopIcon: StopIcon,
|
|
288
|
+
regenerateIcon: RegenerateIcon
|
|
289
|
+
}), {
|
|
290
|
+
icons
|
|
291
|
+
}),
|
|
292
|
+
open,
|
|
293
|
+
setOpen
|
|
294
|
+
}),
|
|
295
|
+
[labels, icons, open, setOpen]
|
|
296
|
+
);
|
|
297
|
+
return /* @__PURE__ */ jsx2(ChatContext.Provider, { value: context, children });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/components/chat/Chat.tsx
|
|
301
|
+
import { useCopilotChat } from "@copilotkit/react-core";
|
|
302
|
+
|
|
303
|
+
// src/components/chat/Window.tsx
|
|
304
|
+
import React2, { useCallback, useEffect } from "react";
|
|
305
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
306
|
+
var Window = ({
|
|
307
|
+
open,
|
|
308
|
+
setOpen,
|
|
309
|
+
children,
|
|
310
|
+
clickOutsideToClose,
|
|
311
|
+
shortcut,
|
|
312
|
+
hitEscapeToClose
|
|
313
|
+
}) => {
|
|
314
|
+
const windowRef = React2.useRef(null);
|
|
315
|
+
const handleClickOutside = useCallback(
|
|
316
|
+
(event) => {
|
|
317
|
+
var _a;
|
|
318
|
+
if (!clickOutsideToClose) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const parentElement = (_a = windowRef.current) == null ? void 0 : _a.parentElement;
|
|
322
|
+
if (open && parentElement && !parentElement.contains(event.target)) {
|
|
323
|
+
setOpen(false);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
[clickOutsideToClose, open, setOpen]
|
|
327
|
+
);
|
|
328
|
+
const handleKeyDown = useCallback(
|
|
329
|
+
(event) => {
|
|
330
|
+
var _a;
|
|
331
|
+
const target = event.target;
|
|
332
|
+
const isInput = target.tagName === "INPUT" || target.tagName === "SELECT" || target.tagName === "TEXTAREA" || target.isContentEditable;
|
|
333
|
+
const isDescendantOfWrapper = (_a = windowRef.current) == null ? void 0 : _a.contains(target);
|
|
334
|
+
if (open && event.key === "Escape" && (!isInput || isDescendantOfWrapper) && hitEscapeToClose) {
|
|
335
|
+
setOpen(false);
|
|
336
|
+
} else if (event.key === shortcut && (isMacOS() && event.metaKey || !isMacOS() && event.ctrlKey) && (!isInput || isDescendantOfWrapper)) {
|
|
337
|
+
setOpen(!open);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
[hitEscapeToClose, shortcut, open, setOpen]
|
|
341
|
+
);
|
|
342
|
+
const adjustForMobile = useCallback(() => {
|
|
343
|
+
const copilotKitWindow = windowRef.current;
|
|
344
|
+
const vv = window.visualViewport;
|
|
345
|
+
if (!copilotKitWindow || !vv) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (window.innerWidth < 640 && open) {
|
|
349
|
+
copilotKitWindow.style.height = `${vv.height}px`;
|
|
350
|
+
copilotKitWindow.style.left = `${vv.offsetLeft}px`;
|
|
351
|
+
copilotKitWindow.style.top = `${vv.offsetTop}px`;
|
|
352
|
+
document.body.style.position = "fixed";
|
|
353
|
+
document.body.style.width = "100%";
|
|
354
|
+
document.body.style.height = `${window.innerHeight}px`;
|
|
355
|
+
document.body.style.overflow = "hidden";
|
|
356
|
+
document.body.style.touchAction = "none";
|
|
357
|
+
document.body.addEventListener("touchmove", preventScroll, {
|
|
358
|
+
passive: false
|
|
359
|
+
});
|
|
360
|
+
} else {
|
|
361
|
+
copilotKitWindow.style.height = "";
|
|
362
|
+
copilotKitWindow.style.left = "";
|
|
363
|
+
copilotKitWindow.style.top = "";
|
|
364
|
+
document.body.style.position = "";
|
|
365
|
+
document.body.style.height = "";
|
|
366
|
+
document.body.style.width = "";
|
|
367
|
+
document.body.style.overflow = "";
|
|
368
|
+
document.body.style.top = "";
|
|
369
|
+
document.body.style.touchAction = "";
|
|
370
|
+
document.body.removeEventListener("touchmove", preventScroll);
|
|
371
|
+
}
|
|
372
|
+
}, [open]);
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
375
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
376
|
+
if (window.visualViewport) {
|
|
377
|
+
window.visualViewport.addEventListener("resize", adjustForMobile);
|
|
378
|
+
adjustForMobile();
|
|
379
|
+
}
|
|
380
|
+
return () => {
|
|
381
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
382
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
383
|
+
if (window.visualViewport) {
|
|
384
|
+
window.visualViewport.removeEventListener("resize", adjustForMobile);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}, [adjustForMobile, handleClickOutside, handleKeyDown]);
|
|
388
|
+
return /* @__PURE__ */ jsx3("div", { className: `copilotKitWindow${open ? " open" : ""}`, ref: windowRef, children });
|
|
389
|
+
};
|
|
390
|
+
var preventScroll = (event) => {
|
|
391
|
+
let targetElement = event.target;
|
|
392
|
+
const hasParentWithClass = (element, className) => {
|
|
393
|
+
while (element && element !== document.body) {
|
|
394
|
+
if (element.classList.contains(className)) {
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
element = element.parentElement;
|
|
398
|
+
}
|
|
399
|
+
return false;
|
|
400
|
+
};
|
|
401
|
+
if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
|
|
402
|
+
event.preventDefault();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
function isMacOS() {
|
|
406
|
+
return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/components/chat/Button.tsx
|
|
410
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
411
|
+
var Button = ({ open, setOpen }) => {
|
|
412
|
+
const context = useChatContext();
|
|
413
|
+
return /* @__PURE__ */ jsx4("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ jsxs2(
|
|
414
|
+
"button",
|
|
415
|
+
{
|
|
416
|
+
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
417
|
+
"aria-label": open ? "Close Chat" : "Open Chat",
|
|
418
|
+
children: [
|
|
419
|
+
/* @__PURE__ */ jsx4("div", { className: "copilotKitButtonIcon copilotKitButtonIconOpen", children: context.icons.openIcon }),
|
|
420
|
+
/* @__PURE__ */ jsx4("div", { className: "copilotKitButtonIcon copilotKitButtonIconClose", children: context.icons.closeIcon })
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
) });
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// src/components/chat/Header.tsx
|
|
427
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
428
|
+
var Header = ({ setOpen }) => {
|
|
429
|
+
const context = useChatContext();
|
|
430
|
+
return /* @__PURE__ */ jsxs3("div", { className: "copilotKitHeader", children: [
|
|
431
|
+
/* @__PURE__ */ jsx5("div", { children: context.labels.title }),
|
|
432
|
+
/* @__PURE__ */ jsx5("button", { onClick: () => setOpen(false), "aria-label": "Close", children: context.icons.headerCloseIcon })
|
|
433
|
+
] });
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
// src/components/chat/Messages.tsx
|
|
437
|
+
import React4, { useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
438
|
+
import { nanoid } from "nanoid";
|
|
439
|
+
import { decodeResult } from "@copilotkit/shared";
|
|
440
|
+
|
|
441
|
+
// src/components/chat/Markdown.tsx
|
|
442
|
+
import { memo as memo2 } from "react";
|
|
443
|
+
import ReactMarkdown from "react-markdown";
|
|
444
|
+
|
|
445
|
+
// src/components/chat/CodeBlock.tsx
|
|
446
|
+
import { memo } from "react";
|
|
447
|
+
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
448
|
+
|
|
449
|
+
// src/hooks/use-copy-to-clipboard.tsx
|
|
450
|
+
import * as React3 from "react";
|
|
451
|
+
function useCopyToClipboard({ timeout = 2e3 }) {
|
|
452
|
+
const [isCopied, setIsCopied] = React3.useState(false);
|
|
453
|
+
const copyToClipboard = (value) => {
|
|
454
|
+
var _a;
|
|
455
|
+
if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (!value) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
462
|
+
setIsCopied(true);
|
|
463
|
+
setTimeout(() => {
|
|
464
|
+
setIsCopied(false);
|
|
465
|
+
}, timeout);
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
return { isCopied, copyToClipboard };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/components/chat/CodeBlock.tsx
|
|
472
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
473
|
+
var programmingLanguages = {
|
|
474
|
+
javascript: ".js",
|
|
475
|
+
python: ".py",
|
|
476
|
+
java: ".java",
|
|
477
|
+
c: ".c",
|
|
478
|
+
cpp: ".cpp",
|
|
479
|
+
"c++": ".cpp",
|
|
480
|
+
"c#": ".cs",
|
|
481
|
+
ruby: ".rb",
|
|
482
|
+
php: ".php",
|
|
483
|
+
swift: ".swift",
|
|
484
|
+
"objective-c": ".m",
|
|
485
|
+
kotlin: ".kt",
|
|
486
|
+
typescript: ".ts",
|
|
487
|
+
go: ".go",
|
|
488
|
+
perl: ".pl",
|
|
489
|
+
rust: ".rs",
|
|
490
|
+
scala: ".scala",
|
|
491
|
+
haskell: ".hs",
|
|
492
|
+
lua: ".lua",
|
|
493
|
+
shell: ".sh",
|
|
494
|
+
sql: ".sql",
|
|
495
|
+
html: ".html",
|
|
496
|
+
css: ".css"
|
|
497
|
+
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
|
|
498
|
+
};
|
|
499
|
+
var generateRandomString = (length, lowercase = false) => {
|
|
500
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
|
|
501
|
+
let result = "";
|
|
502
|
+
for (let i = 0; i < length; i++) {
|
|
503
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
504
|
+
}
|
|
505
|
+
return lowercase ? result.toLowerCase() : result;
|
|
506
|
+
};
|
|
507
|
+
var CodeBlock = memo(({ language, value }) => {
|
|
508
|
+
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
509
|
+
const downloadAsFile = () => {
|
|
510
|
+
if (typeof window === "undefined") {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const fileExtension = programmingLanguages[language] || ".file";
|
|
514
|
+
const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
|
|
515
|
+
const fileName = window.prompt("Enter file name", suggestedFileName);
|
|
516
|
+
if (!fileName) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const blob = new Blob([value], { type: "text/plain" });
|
|
520
|
+
const url = URL.createObjectURL(blob);
|
|
521
|
+
const link = document.createElement("a");
|
|
522
|
+
link.download = fileName;
|
|
523
|
+
link.href = url;
|
|
524
|
+
link.style.display = "none";
|
|
525
|
+
document.body.appendChild(link);
|
|
526
|
+
link.click();
|
|
527
|
+
document.body.removeChild(link);
|
|
528
|
+
URL.revokeObjectURL(url);
|
|
529
|
+
};
|
|
530
|
+
const onCopy = () => {
|
|
531
|
+
if (isCopied)
|
|
532
|
+
return;
|
|
533
|
+
copyToClipboard(value);
|
|
534
|
+
};
|
|
535
|
+
return /* @__PURE__ */ jsxs4("div", { className: "copilotKitCodeBlock", children: [
|
|
536
|
+
/* @__PURE__ */ jsxs4("div", { className: "copilotKitCodeBlockToolbar", children: [
|
|
537
|
+
/* @__PURE__ */ jsx6("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
|
|
538
|
+
/* @__PURE__ */ jsxs4("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
|
|
539
|
+
/* @__PURE__ */ jsxs4("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
|
|
540
|
+
/* @__PURE__ */ jsx6(DownloadIcon, {}),
|
|
541
|
+
/* @__PURE__ */ jsx6("span", { className: "sr-only", children: "Download" })
|
|
542
|
+
] }),
|
|
543
|
+
/* @__PURE__ */ jsxs4("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
|
|
544
|
+
isCopied ? /* @__PURE__ */ jsx6(CheckIcon, {}) : /* @__PURE__ */ jsx6(CopyIcon, {}),
|
|
545
|
+
/* @__PURE__ */ jsx6("span", { className: "sr-only", children: "Copy code" })
|
|
546
|
+
] })
|
|
547
|
+
] })
|
|
548
|
+
] }),
|
|
549
|
+
/* @__PURE__ */ jsx6(
|
|
550
|
+
SyntaxHighlighter,
|
|
551
|
+
{
|
|
552
|
+
language,
|
|
553
|
+
style: highlightStyle,
|
|
554
|
+
PreTag: "div",
|
|
555
|
+
customStyle: {
|
|
556
|
+
margin: 0,
|
|
557
|
+
borderBottomLeftRadius: "0.375rem",
|
|
558
|
+
borderBottomRightRadius: "0.375rem"
|
|
559
|
+
},
|
|
560
|
+
children: value
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
] });
|
|
564
|
+
});
|
|
565
|
+
CodeBlock.displayName = "CodeBlock";
|
|
566
|
+
var highlightStyle = {
|
|
567
|
+
'pre[class*="language-"]': {
|
|
568
|
+
color: "#d4d4d4",
|
|
569
|
+
fontSize: "13px",
|
|
570
|
+
textShadow: "none",
|
|
571
|
+
fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
|
|
572
|
+
direction: "ltr",
|
|
573
|
+
textAlign: "left",
|
|
574
|
+
whiteSpace: "pre",
|
|
575
|
+
wordSpacing: "normal",
|
|
576
|
+
wordBreak: "normal",
|
|
577
|
+
lineHeight: "1.5",
|
|
578
|
+
MozTabSize: "4",
|
|
579
|
+
OTabSize: "4",
|
|
580
|
+
tabSize: "4",
|
|
581
|
+
WebkitHyphens: "none",
|
|
582
|
+
MozHyphens: "none",
|
|
583
|
+
msHyphens: "none",
|
|
584
|
+
hyphens: "none",
|
|
585
|
+
padding: "1em",
|
|
586
|
+
margin: ".5em 0",
|
|
587
|
+
overflow: "auto",
|
|
588
|
+
background: "#1e1e1e"
|
|
589
|
+
},
|
|
590
|
+
'code[class*="language-"]': {
|
|
591
|
+
color: "#d4d4d4",
|
|
592
|
+
fontSize: "13px",
|
|
593
|
+
textShadow: "none",
|
|
594
|
+
fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
|
|
595
|
+
direction: "ltr",
|
|
596
|
+
textAlign: "left",
|
|
597
|
+
whiteSpace: "pre",
|
|
598
|
+
wordSpacing: "normal",
|
|
599
|
+
wordBreak: "normal",
|
|
600
|
+
lineHeight: "1.5",
|
|
601
|
+
MozTabSize: "4",
|
|
602
|
+
OTabSize: "4",
|
|
603
|
+
tabSize: "4",
|
|
604
|
+
WebkitHyphens: "none",
|
|
605
|
+
MozHyphens: "none",
|
|
606
|
+
msHyphens: "none",
|
|
607
|
+
hyphens: "none"
|
|
608
|
+
},
|
|
609
|
+
'pre[class*="language-"]::selection': {
|
|
610
|
+
textShadow: "none",
|
|
611
|
+
background: "#264F78"
|
|
612
|
+
},
|
|
613
|
+
'code[class*="language-"]::selection': {
|
|
614
|
+
textShadow: "none",
|
|
615
|
+
background: "#264F78"
|
|
616
|
+
},
|
|
617
|
+
'pre[class*="language-"] *::selection': {
|
|
618
|
+
textShadow: "none",
|
|
619
|
+
background: "#264F78"
|
|
620
|
+
},
|
|
621
|
+
'code[class*="language-"] *::selection': {
|
|
622
|
+
textShadow: "none",
|
|
623
|
+
background: "#264F78"
|
|
624
|
+
},
|
|
625
|
+
':not(pre) > code[class*="language-"]': {
|
|
626
|
+
padding: ".1em .3em",
|
|
627
|
+
borderRadius: ".3em",
|
|
628
|
+
color: "#db4c69",
|
|
629
|
+
background: "#1e1e1e"
|
|
630
|
+
},
|
|
631
|
+
".namespace": {
|
|
632
|
+
Opacity: ".7"
|
|
633
|
+
},
|
|
634
|
+
"doctype.doctype-tag": {
|
|
635
|
+
color: "#569CD6"
|
|
636
|
+
},
|
|
637
|
+
"doctype.name": {
|
|
638
|
+
color: "#9cdcfe"
|
|
639
|
+
},
|
|
640
|
+
comment: {
|
|
641
|
+
color: "#6a9955"
|
|
642
|
+
},
|
|
643
|
+
prolog: {
|
|
644
|
+
color: "#6a9955"
|
|
645
|
+
},
|
|
646
|
+
punctuation: {
|
|
647
|
+
color: "#d4d4d4"
|
|
648
|
+
},
|
|
649
|
+
".language-html .language-css .token.punctuation": {
|
|
650
|
+
color: "#d4d4d4"
|
|
651
|
+
},
|
|
652
|
+
".language-html .language-javascript .token.punctuation": {
|
|
653
|
+
color: "#d4d4d4"
|
|
654
|
+
},
|
|
655
|
+
property: {
|
|
656
|
+
color: "#9cdcfe"
|
|
657
|
+
},
|
|
658
|
+
tag: {
|
|
659
|
+
color: "#569cd6"
|
|
660
|
+
},
|
|
661
|
+
boolean: {
|
|
662
|
+
color: "#569cd6"
|
|
663
|
+
},
|
|
664
|
+
number: {
|
|
665
|
+
color: "#b5cea8"
|
|
666
|
+
},
|
|
667
|
+
constant: {
|
|
668
|
+
color: "#9cdcfe"
|
|
669
|
+
},
|
|
670
|
+
symbol: {
|
|
671
|
+
color: "#b5cea8"
|
|
672
|
+
},
|
|
673
|
+
inserted: {
|
|
674
|
+
color: "#b5cea8"
|
|
675
|
+
},
|
|
676
|
+
unit: {
|
|
677
|
+
color: "#b5cea8"
|
|
678
|
+
},
|
|
679
|
+
selector: {
|
|
680
|
+
color: "#d7ba7d"
|
|
681
|
+
},
|
|
682
|
+
"attr-name": {
|
|
683
|
+
color: "#9cdcfe"
|
|
684
|
+
},
|
|
685
|
+
string: {
|
|
686
|
+
color: "#ce9178"
|
|
687
|
+
},
|
|
688
|
+
char: {
|
|
689
|
+
color: "#ce9178"
|
|
690
|
+
},
|
|
691
|
+
builtin: {
|
|
692
|
+
color: "#ce9178"
|
|
693
|
+
},
|
|
694
|
+
deleted: {
|
|
695
|
+
color: "#ce9178"
|
|
696
|
+
},
|
|
697
|
+
".language-css .token.string.url": {
|
|
698
|
+
textDecoration: "underline"
|
|
699
|
+
},
|
|
700
|
+
operator: {
|
|
701
|
+
color: "#d4d4d4"
|
|
702
|
+
},
|
|
703
|
+
entity: {
|
|
704
|
+
color: "#569cd6"
|
|
705
|
+
},
|
|
706
|
+
"operator.arrow": {
|
|
707
|
+
color: "#569CD6"
|
|
708
|
+
},
|
|
709
|
+
atrule: {
|
|
710
|
+
color: "#ce9178"
|
|
711
|
+
},
|
|
712
|
+
"atrule.rule": {
|
|
713
|
+
color: "#c586c0"
|
|
714
|
+
},
|
|
715
|
+
"atrule.url": {
|
|
716
|
+
color: "#9cdcfe"
|
|
717
|
+
},
|
|
718
|
+
"atrule.url.function": {
|
|
719
|
+
color: "#dcdcaa"
|
|
720
|
+
},
|
|
721
|
+
"atrule.url.punctuation": {
|
|
722
|
+
color: "#d4d4d4"
|
|
723
|
+
},
|
|
724
|
+
keyword: {
|
|
725
|
+
color: "#569CD6"
|
|
726
|
+
},
|
|
727
|
+
"keyword.module": {
|
|
728
|
+
color: "#c586c0"
|
|
729
|
+
},
|
|
730
|
+
"keyword.control-flow": {
|
|
731
|
+
color: "#c586c0"
|
|
732
|
+
},
|
|
733
|
+
function: {
|
|
734
|
+
color: "#dcdcaa"
|
|
735
|
+
},
|
|
736
|
+
"function.maybe-class-name": {
|
|
737
|
+
color: "#dcdcaa"
|
|
738
|
+
},
|
|
739
|
+
regex: {
|
|
740
|
+
color: "#d16969"
|
|
741
|
+
},
|
|
742
|
+
important: {
|
|
743
|
+
color: "#569cd6"
|
|
744
|
+
},
|
|
745
|
+
italic: {
|
|
746
|
+
fontStyle: "italic"
|
|
747
|
+
},
|
|
748
|
+
"class-name": {
|
|
749
|
+
color: "#4ec9b0"
|
|
750
|
+
},
|
|
751
|
+
"maybe-class-name": {
|
|
752
|
+
color: "#4ec9b0"
|
|
753
|
+
},
|
|
754
|
+
console: {
|
|
755
|
+
color: "#9cdcfe"
|
|
756
|
+
},
|
|
757
|
+
parameter: {
|
|
758
|
+
color: "#9cdcfe"
|
|
759
|
+
},
|
|
760
|
+
interpolation: {
|
|
761
|
+
color: "#9cdcfe"
|
|
762
|
+
},
|
|
763
|
+
"punctuation.interpolation-punctuation": {
|
|
764
|
+
color: "#569cd6"
|
|
765
|
+
},
|
|
766
|
+
variable: {
|
|
767
|
+
color: "#9cdcfe"
|
|
768
|
+
},
|
|
769
|
+
"imports.maybe-class-name": {
|
|
770
|
+
color: "#9cdcfe"
|
|
771
|
+
},
|
|
772
|
+
"exports.maybe-class-name": {
|
|
773
|
+
color: "#9cdcfe"
|
|
774
|
+
},
|
|
775
|
+
escape: {
|
|
776
|
+
color: "#d7ba7d"
|
|
777
|
+
},
|
|
778
|
+
"tag.punctuation": {
|
|
779
|
+
color: "#808080"
|
|
780
|
+
},
|
|
781
|
+
cdata: {
|
|
782
|
+
color: "#808080"
|
|
783
|
+
},
|
|
784
|
+
"attr-value": {
|
|
785
|
+
color: "#ce9178"
|
|
786
|
+
},
|
|
787
|
+
"attr-value.punctuation": {
|
|
788
|
+
color: "#ce9178"
|
|
789
|
+
},
|
|
790
|
+
"attr-value.punctuation.attr-equals": {
|
|
791
|
+
color: "#d4d4d4"
|
|
792
|
+
},
|
|
793
|
+
namespace: {
|
|
794
|
+
color: "#4ec9b0"
|
|
795
|
+
},
|
|
796
|
+
'pre[class*="language-javascript"]': {
|
|
797
|
+
color: "#9cdcfe"
|
|
798
|
+
},
|
|
799
|
+
'code[class*="language-javascript"]': {
|
|
800
|
+
color: "#9cdcfe"
|
|
801
|
+
},
|
|
802
|
+
'pre[class*="language-jsx"]': {
|
|
803
|
+
color: "#9cdcfe"
|
|
804
|
+
},
|
|
805
|
+
'code[class*="language-jsx"]': {
|
|
806
|
+
color: "#9cdcfe"
|
|
807
|
+
},
|
|
808
|
+
'pre[class*="language-typescript"]': {
|
|
809
|
+
color: "#9cdcfe"
|
|
810
|
+
},
|
|
811
|
+
'code[class*="language-typescript"]': {
|
|
812
|
+
color: "#9cdcfe"
|
|
813
|
+
},
|
|
814
|
+
'pre[class*="language-tsx"]': {
|
|
815
|
+
color: "#9cdcfe"
|
|
816
|
+
},
|
|
817
|
+
'code[class*="language-tsx"]': {
|
|
818
|
+
color: "#9cdcfe"
|
|
819
|
+
},
|
|
820
|
+
'pre[class*="language-css"]': {
|
|
821
|
+
color: "#ce9178"
|
|
822
|
+
},
|
|
823
|
+
'code[class*="language-css"]': {
|
|
824
|
+
color: "#ce9178"
|
|
825
|
+
},
|
|
826
|
+
'pre[class*="language-html"]': {
|
|
827
|
+
color: "#d4d4d4"
|
|
828
|
+
},
|
|
829
|
+
'code[class*="language-html"]': {
|
|
830
|
+
color: "#d4d4d4"
|
|
831
|
+
},
|
|
832
|
+
".language-regex .token.anchor": {
|
|
833
|
+
color: "#dcdcaa"
|
|
834
|
+
},
|
|
835
|
+
".language-html .token.punctuation": {
|
|
836
|
+
color: "#808080"
|
|
837
|
+
},
|
|
838
|
+
'pre[class*="language-"] > code[class*="language-"]': {
|
|
839
|
+
position: "relative",
|
|
840
|
+
zIndex: "1"
|
|
841
|
+
},
|
|
842
|
+
".line-highlight.line-highlight": {
|
|
843
|
+
background: "#f7ebc6",
|
|
844
|
+
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
845
|
+
zIndex: "0"
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// src/components/chat/Markdown.tsx
|
|
850
|
+
import remarkGfm from "remark-gfm";
|
|
851
|
+
import remarkMath from "remark-math";
|
|
852
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
853
|
+
var MemoizedReactMarkdown = memo2(
|
|
854
|
+
ReactMarkdown,
|
|
855
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
856
|
+
);
|
|
857
|
+
var Markdown = ({ content }) => {
|
|
858
|
+
return /* @__PURE__ */ jsx7("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ jsx7(MemoizedReactMarkdown, { components, remarkPlugins: [remarkGfm, remarkMath], children: content }) });
|
|
859
|
+
};
|
|
860
|
+
var components = {
|
|
861
|
+
p({ children }) {
|
|
862
|
+
return /* @__PURE__ */ jsx7("p", { children });
|
|
863
|
+
},
|
|
864
|
+
a(_a) {
|
|
865
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
866
|
+
return /* @__PURE__ */ jsx7(
|
|
867
|
+
"a",
|
|
868
|
+
__spreadProps(__spreadValues({
|
|
869
|
+
style: { color: "blue", textDecoration: "underline" }
|
|
870
|
+
}, props), {
|
|
871
|
+
target: "_blank",
|
|
872
|
+
rel: "noopener noreferrer",
|
|
873
|
+
children
|
|
874
|
+
})
|
|
875
|
+
);
|
|
876
|
+
},
|
|
877
|
+
code(_c) {
|
|
878
|
+
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
879
|
+
if (children.length) {
|
|
880
|
+
if (children[0] == "\u258D") {
|
|
881
|
+
return /* @__PURE__ */ jsx7(
|
|
882
|
+
"span",
|
|
883
|
+
{
|
|
884
|
+
style: {
|
|
885
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
886
|
+
marginTop: "0.25rem"
|
|
887
|
+
},
|
|
888
|
+
children: "\u258D"
|
|
889
|
+
}
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
893
|
+
}
|
|
894
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
895
|
+
if (inline) {
|
|
896
|
+
return /* @__PURE__ */ jsx7("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
897
|
+
}
|
|
898
|
+
return /* @__PURE__ */ jsx7(
|
|
899
|
+
CodeBlock,
|
|
900
|
+
__spreadValues({
|
|
901
|
+
language: match && match[1] || "",
|
|
902
|
+
value: String(children).replace(/\n$/, "")
|
|
903
|
+
}, props),
|
|
904
|
+
Math.random()
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
// src/components/chat/Messages.tsx
|
|
910
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
911
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
912
|
+
var Messages = ({ messages, inProgress }) => {
|
|
913
|
+
const { chatComponentsCache } = useCopilotContext();
|
|
914
|
+
const context = useChatContext();
|
|
915
|
+
const initialMessages = useMemo2(
|
|
916
|
+
() => makeInitialMessages(context.labels.initial),
|
|
917
|
+
[context.labels.initial]
|
|
918
|
+
);
|
|
919
|
+
messages = [...initialMessages, ...messages];
|
|
920
|
+
const functionResults = {};
|
|
921
|
+
for (let i = 0; i < messages.length; i++) {
|
|
922
|
+
if (messages[i].role === "assistant" && messages[i].function_call) {
|
|
923
|
+
const id = messages[i].id;
|
|
924
|
+
if (i + 1 < messages.length && messages[i + 1].role === "function") {
|
|
925
|
+
functionResults[id] = decodeResult(messages[i + 1].content || "");
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
const messagesEndRef = React4.useRef(null);
|
|
930
|
+
const scrollToBottom = () => {
|
|
931
|
+
if (messagesEndRef.current) {
|
|
932
|
+
messagesEndRef.current.scrollIntoView({
|
|
933
|
+
behavior: "auto"
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
useEffect2(() => {
|
|
938
|
+
scrollToBottom();
|
|
939
|
+
}, [messages]);
|
|
940
|
+
return /* @__PURE__ */ jsxs5("div", { className: "copilotKitMessages", children: [
|
|
941
|
+
messages.map((message, index) => {
|
|
942
|
+
var _a, _b, _c;
|
|
943
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
944
|
+
if (message.role === "user") {
|
|
945
|
+
return /* @__PURE__ */ jsx8("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
946
|
+
} else if (message.role == "assistant") {
|
|
947
|
+
if (isCurrentMessage && inProgress && !message.content && !message.partialFunctionCall) {
|
|
948
|
+
return /* @__PURE__ */ jsx8("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
949
|
+
} else if (message.function_call || message.partialFunctionCall) {
|
|
950
|
+
const functionCallName = ((_a = message.function_call) == null ? void 0 : _a.name) || ((_b = message.partialFunctionCall) == null ? void 0 : _b.name);
|
|
951
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current[functionCallName]) {
|
|
952
|
+
const render = chatComponentsCache.current[functionCallName];
|
|
953
|
+
if (typeof render === "string") {
|
|
954
|
+
if (isCurrentMessage && inProgress) {
|
|
955
|
+
return /* @__PURE__ */ jsxs5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
956
|
+
context.icons.spinnerIcon,
|
|
957
|
+
" ",
|
|
958
|
+
/* @__PURE__ */ jsx8("span", { className: "inProgressLabel", children: render })
|
|
959
|
+
] }, index);
|
|
960
|
+
} else {
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
} else {
|
|
964
|
+
const args = message.function_call ? JSON.parse(message.function_call.arguments || "{}") : (_c = message.partialFunctionCall) == null ? void 0 : _c.arguments;
|
|
965
|
+
let status = "inProgress";
|
|
966
|
+
if (functionResults[message.id] !== void 0) {
|
|
967
|
+
status = "complete";
|
|
968
|
+
} else if (message.function_call) {
|
|
969
|
+
status = "executing";
|
|
970
|
+
}
|
|
971
|
+
const toRender = render({
|
|
972
|
+
status,
|
|
973
|
+
args,
|
|
974
|
+
result: functionResults[message.id]
|
|
975
|
+
});
|
|
976
|
+
if (!toRender && status === "complete") {
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
if (typeof toRender === "string") {
|
|
980
|
+
return /* @__PURE__ */ jsxs5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
981
|
+
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
982
|
+
" ",
|
|
983
|
+
toRender
|
|
984
|
+
] }, index);
|
|
985
|
+
} else {
|
|
986
|
+
return /* @__PURE__ */ jsx8("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
} else if ((!inProgress || !isCurrentMessage) && message.function_call) {
|
|
990
|
+
return null;
|
|
991
|
+
} else {
|
|
992
|
+
return /* @__PURE__ */ jsx8("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return /* @__PURE__ */ jsx8("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ jsx8(Markdown, { content: message.content }) }, index);
|
|
996
|
+
}
|
|
997
|
+
}),
|
|
998
|
+
/* @__PURE__ */ jsx8("div", { ref: messagesEndRef })
|
|
999
|
+
] });
|
|
1000
|
+
};
|
|
1001
|
+
function makeInitialMessages(initial) {
|
|
1002
|
+
let initialArray = [];
|
|
1003
|
+
if (initial) {
|
|
1004
|
+
if (Array.isArray(initial)) {
|
|
1005
|
+
initialArray.push(...initial);
|
|
1006
|
+
} else {
|
|
1007
|
+
initialArray.push(initial);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return initialArray.map((message) => ({
|
|
1011
|
+
id: nanoid(),
|
|
1012
|
+
role: "assistant",
|
|
1013
|
+
content: message
|
|
1014
|
+
}));
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// src/components/chat/Input.tsx
|
|
1018
|
+
import { useEffect as useEffect4, useRef as useRef2, useState as useState3 } from "react";
|
|
1019
|
+
|
|
1020
|
+
// src/components/chat/Textarea.tsx
|
|
1021
|
+
import { useState as useState2, useRef, useEffect as useEffect3, forwardRef, useImperativeHandle } from "react";
|
|
1022
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1023
|
+
var AutoResizingTextarea = forwardRef(
|
|
1024
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1025
|
+
const internalTextareaRef = useRef(null);
|
|
1026
|
+
const [maxHeight, setMaxHeight] = useState2(0);
|
|
1027
|
+
useImperativeHandle(ref, () => internalTextareaRef.current);
|
|
1028
|
+
useEffect3(() => {
|
|
1029
|
+
const calculateMaxHeight = () => {
|
|
1030
|
+
const textarea = internalTextareaRef.current;
|
|
1031
|
+
if (textarea) {
|
|
1032
|
+
textarea.style.height = "auto";
|
|
1033
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
1034
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
1035
|
+
if (autoFocus) {
|
|
1036
|
+
textarea.focus();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
calculateMaxHeight();
|
|
1041
|
+
}, [maxRows]);
|
|
1042
|
+
useEffect3(() => {
|
|
1043
|
+
const textarea = internalTextareaRef.current;
|
|
1044
|
+
if (textarea) {
|
|
1045
|
+
textarea.style.height = "auto";
|
|
1046
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
1047
|
+
}
|
|
1048
|
+
}, [value, maxHeight]);
|
|
1049
|
+
return /* @__PURE__ */ jsx9(
|
|
1050
|
+
"textarea",
|
|
1051
|
+
{
|
|
1052
|
+
ref: internalTextareaRef,
|
|
1053
|
+
value,
|
|
1054
|
+
onChange,
|
|
1055
|
+
onKeyDown,
|
|
1056
|
+
placeholder,
|
|
1057
|
+
style: {
|
|
1058
|
+
overflow: "hidden",
|
|
1059
|
+
resize: "none",
|
|
1060
|
+
maxHeight: `${maxHeight}px`
|
|
1061
|
+
},
|
|
1062
|
+
rows: 1
|
|
1063
|
+
}
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
);
|
|
1067
|
+
var Textarea_default = AutoResizingTextarea;
|
|
1068
|
+
|
|
1069
|
+
// src/components/chat/Input.tsx
|
|
1070
|
+
import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1071
|
+
var Input = ({ inProgress, onSend, children, isVisible = false }) => {
|
|
1072
|
+
const context = useChatContext();
|
|
1073
|
+
const textareaRef = useRef2(null);
|
|
1074
|
+
const handleDivClick = (event) => {
|
|
1075
|
+
var _a;
|
|
1076
|
+
if (event.target !== event.currentTarget)
|
|
1077
|
+
return;
|
|
1078
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1079
|
+
};
|
|
1080
|
+
const [text, setText] = useState3("");
|
|
1081
|
+
const send = () => {
|
|
1082
|
+
var _a;
|
|
1083
|
+
if (inProgress)
|
|
1084
|
+
return;
|
|
1085
|
+
onSend(text);
|
|
1086
|
+
setText("");
|
|
1087
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1088
|
+
};
|
|
1089
|
+
useEffect4(() => {
|
|
1090
|
+
var _a;
|
|
1091
|
+
if (isVisible) {
|
|
1092
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1093
|
+
}
|
|
1094
|
+
}, [isVisible]);
|
|
1095
|
+
const icon = inProgress ? context.icons.activityIcon : context.icons.sendIcon;
|
|
1096
|
+
const disabled = inProgress || text.length === 0;
|
|
1097
|
+
return /* @__PURE__ */ jsxs6("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
1098
|
+
/* @__PURE__ */ jsx10("span", { children }),
|
|
1099
|
+
/* @__PURE__ */ jsx10("button", { className: "copilotKitSendButton", disabled, onClick: send, children: icon }),
|
|
1100
|
+
/* @__PURE__ */ jsx10(
|
|
1101
|
+
Textarea_default,
|
|
1102
|
+
{
|
|
1103
|
+
ref: textareaRef,
|
|
1104
|
+
placeholder: context.labels.placeholder,
|
|
1105
|
+
autoFocus: true,
|
|
1106
|
+
maxRows: 5,
|
|
1107
|
+
value: text,
|
|
1108
|
+
onChange: (event) => setText(event.target.value),
|
|
1109
|
+
onKeyDown: (event) => {
|
|
1110
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1111
|
+
event.preventDefault();
|
|
1112
|
+
send();
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
)
|
|
1117
|
+
] });
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
// src/components/chat/Chat.tsx
|
|
1121
|
+
import { nanoid as nanoid2 } from "nanoid";
|
|
1122
|
+
|
|
1123
|
+
// src/components/chat/Response.tsx
|
|
1124
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1125
|
+
var ResponseButton = ({ onClick, inProgress }) => {
|
|
1126
|
+
const context = useChatContext();
|
|
1127
|
+
return /* @__PURE__ */ jsxs7("button", { onClick, className: "copilotKitResponseButton", children: [
|
|
1128
|
+
/* @__PURE__ */ jsx11("span", { children: inProgress ? context.icons.stopIcon : context.icons.regenerateIcon }),
|
|
1129
|
+
inProgress ? context.labels.stopGenerating : context.labels.regenerateResponse
|
|
1130
|
+
] });
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
// src/components/chat/Chat.tsx
|
|
1134
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1135
|
+
var CopilotChat = ({
|
|
1136
|
+
instructions,
|
|
1137
|
+
defaultOpen = false,
|
|
1138
|
+
clickOutsideToClose = true,
|
|
1139
|
+
hitEscapeToClose = true,
|
|
1140
|
+
onSetOpen,
|
|
1141
|
+
onSubmitMessage,
|
|
1142
|
+
shortcut = "/",
|
|
1143
|
+
icons,
|
|
1144
|
+
labels,
|
|
1145
|
+
makeSystemMessage,
|
|
1146
|
+
showResponseButton = true,
|
|
1147
|
+
onInProgress,
|
|
1148
|
+
Window: Window2 = Window,
|
|
1149
|
+
Button: Button2 = Button,
|
|
1150
|
+
Header: Header2 = Header,
|
|
1151
|
+
Messages: Messages2 = Messages,
|
|
1152
|
+
Input: Input2 = Input,
|
|
1153
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1154
|
+
className,
|
|
1155
|
+
children
|
|
1156
|
+
}) => {
|
|
1157
|
+
const { visibleMessages, append, reload, stop, isLoading, input, setInput } = useCopilotChat({
|
|
1158
|
+
id: nanoid2(),
|
|
1159
|
+
makeSystemMessage,
|
|
1160
|
+
additionalInstructions: instructions
|
|
1161
|
+
});
|
|
1162
|
+
useEffect5(() => {
|
|
1163
|
+
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1164
|
+
}, [isLoading]);
|
|
1165
|
+
const [openState, setOpenState] = React7.useState(defaultOpen);
|
|
1166
|
+
const setOpen = (open) => {
|
|
1167
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1168
|
+
setOpenState(open);
|
|
1169
|
+
};
|
|
1170
|
+
const sendMessage = (message) => __async(void 0, null, function* () {
|
|
1171
|
+
onSubmitMessage == null ? void 0 : onSubmitMessage(message);
|
|
1172
|
+
append({
|
|
1173
|
+
id: nanoid2(),
|
|
1174
|
+
content: message,
|
|
1175
|
+
role: "user"
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
return /* @__PURE__ */ jsxs8(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1179
|
+
children,
|
|
1180
|
+
/* @__PURE__ */ jsxs8("div", { className, children: [
|
|
1181
|
+
/* @__PURE__ */ jsx12(Button2, { open: openState, setOpen }),
|
|
1182
|
+
/* @__PURE__ */ jsxs8(
|
|
1183
|
+
Window2,
|
|
1184
|
+
{
|
|
1185
|
+
open: openState,
|
|
1186
|
+
setOpen,
|
|
1187
|
+
clickOutsideToClose,
|
|
1188
|
+
shortcut,
|
|
1189
|
+
hitEscapeToClose,
|
|
1190
|
+
children: [
|
|
1191
|
+
/* @__PURE__ */ jsx12(Header2, { open: openState, setOpen }),
|
|
1192
|
+
/* @__PURE__ */ jsx12(Messages2, { messages: visibleMessages, inProgress: isLoading }),
|
|
1193
|
+
/* @__PURE__ */ jsx12(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: openState, children: showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ jsx12(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading }) })
|
|
1194
|
+
]
|
|
1195
|
+
}
|
|
1196
|
+
)
|
|
1197
|
+
] })
|
|
1198
|
+
] });
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// src/components/chat/Popup.tsx
|
|
1202
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
1203
|
+
var CopilotPopup = (props) => {
|
|
1204
|
+
props = __spreadProps(__spreadValues({}, props), {
|
|
1205
|
+
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
1206
|
+
});
|
|
1207
|
+
return /* @__PURE__ */ jsx13(CopilotChat, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
// src/components/chat/Sidebar.tsx
|
|
1211
|
+
import { useState as useState4 } from "react";
|
|
1212
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1213
|
+
var CopilotSidebar = (props) => {
|
|
1214
|
+
props = __spreadProps(__spreadValues({}, props), {
|
|
1215
|
+
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
1216
|
+
});
|
|
1217
|
+
const [expandedClassName, setExpandedClassName] = useState4(
|
|
1218
|
+
props.defaultOpen ? "sidebarExpanded" : ""
|
|
1219
|
+
);
|
|
1220
|
+
const onSetOpen = (open) => {
|
|
1221
|
+
var _a;
|
|
1222
|
+
(_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
|
|
1223
|
+
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
1224
|
+
};
|
|
1225
|
+
return /* @__PURE__ */ jsx14("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ jsx14(CopilotChat, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
|
|
1226
|
+
};
|
|
30
1227
|
export {
|
|
31
1228
|
CopilotPopup,
|
|
32
1229
|
CopilotSidebar,
|