@copilotkit/react-ui 1.8.6 → 1.8.7
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/CHANGELOG.md +20 -0
- package/dist/{chunk-Q2YY2NX3.mjs → chunk-24TDU7MY.mjs} +2 -2
- package/dist/{chunk-XNQO5AZZ.mjs → chunk-ABHUX6T6.mjs} +2 -2
- package/dist/{chunk-QJKMOGWN.mjs → chunk-BDNHZ3GW.mjs} +4 -3
- package/dist/chunk-BDNHZ3GW.mjs.map +1 -0
- package/dist/{chunk-NMNC4ROZ.mjs → chunk-DSQGQJI4.mjs} +2 -2
- package/dist/{chunk-HEIDCT7I.mjs → chunk-HWMFMBJC.mjs} +2 -2
- package/dist/chunk-HWMFMBJC.mjs.map +1 -0
- package/dist/{chunk-UN2E3HCK.mjs → chunk-IEMQ2SQW.mjs} +6 -4
- package/dist/chunk-IEMQ2SQW.mjs.map +1 -0
- package/dist/{chunk-ZY25LVYR.mjs → chunk-IJADIQAR.mjs} +20 -2
- package/dist/chunk-IJADIQAR.mjs.map +1 -0
- package/dist/{chunk-X6EFGEBJ.mjs → chunk-JOL7NS2W.mjs} +2 -2
- package/dist/{chunk-PCTCOQK2.mjs → chunk-KENCH7RN.mjs} +2 -2
- package/dist/{chunk-ZLRUNNS7.mjs → chunk-O34Z4XM2.mjs} +170 -30
- package/dist/chunk-O34Z4XM2.mjs.map +1 -0
- package/dist/{chunk-5M7ODWKH.mjs → chunk-OZXUB3V7.mjs} +3 -3
- package/dist/chunk-PLHTVHUW.mjs +82 -0
- package/dist/chunk-PLHTVHUW.mjs.map +1 -0
- package/dist/{chunk-62QMTKMJ.mjs → chunk-POWCBXRY.mjs} +3 -3
- package/dist/chunk-PXEVB7IK.mjs +1 -0
- package/dist/{chunk-HIORSNVD.mjs → chunk-Q2NFQTCQ.mjs} +2 -2
- package/dist/chunk-SLTG4L62.mjs +78 -0
- package/dist/chunk-SLTG4L62.mjs.map +1 -0
- package/dist/{chunk-SMJ3QQCE.mjs → chunk-T7N77F5Y.mjs} +2 -2
- package/dist/{chunk-YOEL33HG.mjs → chunk-UFN2VWSR.mjs} +2 -2
- package/dist/{chunk-2OTVZXDX.mjs → chunk-UH2UFL5W.mjs} +3 -3
- package/dist/{chunk-D5XIJNXQ.mjs → chunk-VGPQYMKJ.mjs} +8 -8
- package/dist/{chunk-WNC6OCIB.mjs → chunk-XFCMZH2H.mjs} +2 -2
- package/dist/{chunk-ORSMX3SE.mjs → chunk-XWG3L6QC.mjs} +15 -1
- package/dist/{chunk-ORSMX3SE.mjs.map → chunk-XWG3L6QC.mjs.map} +1 -1
- package/dist/{chunk-TOQ7P4DO.mjs → chunk-XZNY26GH.mjs} +2 -2
- package/dist/{chunk-GOAED4H6.mjs → chunk-Y7UO3RPW.mjs} +10 -10
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.d.ts +23 -3
- package/dist/components/chat/Chat.js +341 -30
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +16 -14
- package/dist/components/chat/ChatContext.d.ts +5 -0
- package/dist/components/chat/ChatContext.js +15 -1
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +2 -2
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +5 -5
- package/dist/components/chat/Icons.d.ts +2 -1
- package/dist/components/chat/Icons.js +17 -2
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +5 -3
- package/dist/components/chat/ImageUploadQueue.d.ts +13 -0
- package/dist/components/chat/ImageUploadQueue.js +106 -0
- package/dist/components/chat/ImageUploadQueue.js.map +1 -0
- package/dist/components/chat/ImageUploadQueue.mjs +8 -0
- package/dist/components/chat/ImageUploadQueue.mjs.map +1 -0
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +2 -1
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +3 -3
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +3 -3
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +18 -0
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +3 -3
- package/dist/components/chat/Modal.js +348 -37
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +22 -20
- package/dist/components/chat/Popup.js +350 -39
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +23 -21
- package/dist/components/chat/Sidebar.js +350 -39
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +23 -21
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +2 -2
- package/dist/components/chat/Window.js.map +1 -1
- package/dist/components/chat/Window.mjs +3 -3
- package/dist/components/chat/index.d.ts +1 -0
- package/dist/components/chat/index.js +354 -41
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +30 -25
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +5 -5
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +6 -6
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +6 -6
- package/dist/components/chat/messages/RenderImageMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderImageMessage.js +774 -0
- package/dist/components/chat/messages/RenderImageMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderImageMessage.mjs +15 -0
- package/dist/components/chat/messages/RenderImageMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderResultMessage.mjs +6 -6
- package/dist/components/chat/messages/RenderTextMessage.js +1 -1
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderTextMessage.mjs +7 -7
- package/dist/components/chat/messages/UserMessage.js +1 -1
- package/dist/components/chat/messages/UserMessage.js.map +1 -1
- package/dist/components/chat/messages/UserMessage.mjs +1 -1
- package/dist/components/chat/props.d.ts +3 -0
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +3 -3
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +3 -3
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +354 -41
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +30 -25
- package/dist/index.d.ts +1 -0
- package/dist/index.js +354 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -25
- package/package.json +6 -6
- package/src/components/chat/Chat.tsx +198 -18
- package/src/components/chat/ChatContext.tsx +7 -0
- package/src/components/chat/Icons.tsx +14 -0
- package/src/components/chat/ImageUploadQueue.tsx +77 -0
- package/src/components/chat/Input.tsx +8 -1
- package/src/components/chat/Messages.tsx +17 -0
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/messages/RenderImageMessage.tsx +64 -0
- package/src/components/chat/messages/UserMessage.tsx +5 -1
- package/src/components/chat/props.ts +3 -0
- package/dist/chunk-HEIDCT7I.mjs.map +0 -1
- package/dist/chunk-QJKMOGWN.mjs.map +0 -1
- package/dist/chunk-SQMEPWVT.mjs +0 -1
- package/dist/chunk-UN2E3HCK.mjs.map +0 -1
- package/dist/chunk-ZLRUNNS7.mjs.map +0 -1
- package/dist/chunk-ZY25LVYR.mjs.map +0 -1
- /package/dist/{chunk-Q2YY2NX3.mjs.map → chunk-24TDU7MY.mjs.map} +0 -0
- /package/dist/{chunk-XNQO5AZZ.mjs.map → chunk-ABHUX6T6.mjs.map} +0 -0
- /package/dist/{chunk-NMNC4ROZ.mjs.map → chunk-DSQGQJI4.mjs.map} +0 -0
- /package/dist/{chunk-X6EFGEBJ.mjs.map → chunk-JOL7NS2W.mjs.map} +0 -0
- /package/dist/{chunk-PCTCOQK2.mjs.map → chunk-KENCH7RN.mjs.map} +0 -0
- /package/dist/{chunk-5M7ODWKH.mjs.map → chunk-OZXUB3V7.mjs.map} +0 -0
- /package/dist/{chunk-62QMTKMJ.mjs.map → chunk-POWCBXRY.mjs.map} +0 -0
- /package/dist/{chunk-SQMEPWVT.mjs.map → chunk-PXEVB7IK.mjs.map} +0 -0
- /package/dist/{chunk-HIORSNVD.mjs.map → chunk-Q2NFQTCQ.mjs.map} +0 -0
- /package/dist/{chunk-SMJ3QQCE.mjs.map → chunk-T7N77F5Y.mjs.map} +0 -0
- /package/dist/{chunk-YOEL33HG.mjs.map → chunk-UFN2VWSR.mjs.map} +0 -0
- /package/dist/{chunk-2OTVZXDX.mjs.map → chunk-UH2UFL5W.mjs.map} +0 -0
- /package/dist/{chunk-D5XIJNXQ.mjs.map → chunk-VGPQYMKJ.mjs.map} +0 -0
- /package/dist/{chunk-WNC6OCIB.mjs.map → chunk-XFCMZH2H.mjs.map} +0 -0
- /package/dist/{chunk-TOQ7P4DO.mjs.map → chunk-XZNY26GH.mjs.map} +0 -0
- /package/dist/{chunk-GOAED4H6.mjs.map → chunk-Y7UO3RPW.mjs.map} +0 -0
|
@@ -298,6 +298,19 @@ var DownloadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
|
298
298
|
)
|
|
299
299
|
}
|
|
300
300
|
);
|
|
301
|
+
var UploadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
302
|
+
"svg",
|
|
303
|
+
{
|
|
304
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
305
|
+
fill: "none",
|
|
306
|
+
viewBox: "0 0 24 24",
|
|
307
|
+
strokeWidth: "1.5",
|
|
308
|
+
stroke: "currentColor",
|
|
309
|
+
width: "24",
|
|
310
|
+
height: "24",
|
|
311
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 4.5v15m7.5-7.5h-15" })
|
|
312
|
+
}
|
|
313
|
+
);
|
|
301
314
|
var CheckIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
302
315
|
"svg",
|
|
303
316
|
{
|
|
@@ -363,7 +376,8 @@ var ChatContextProvider = ({
|
|
|
363
376
|
pushToTalkIcon: MicrophoneIcon,
|
|
364
377
|
copyIcon: CopyIcon,
|
|
365
378
|
thumbsUpIcon: ThumbsUpIcon,
|
|
366
|
-
thumbsDownIcon: ThumbsDownIcon
|
|
379
|
+
thumbsDownIcon: ThumbsDownIcon,
|
|
380
|
+
uploadIcon: UploadIcon
|
|
367
381
|
}), icons),
|
|
368
382
|
[icons]
|
|
369
383
|
);
|
|
@@ -1068,6 +1082,7 @@ var Messages = ({
|
|
|
1068
1082
|
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
1069
1083
|
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
1070
1084
|
RenderResultMessage: RenderResultMessage2,
|
|
1085
|
+
RenderImageMessage: RenderImageMessage2,
|
|
1071
1086
|
AssistantMessage: AssistantMessage2,
|
|
1072
1087
|
UserMessage: UserMessage2,
|
|
1073
1088
|
onRegenerate,
|
|
@@ -1156,6 +1171,23 @@ var Messages = ({
|
|
|
1156
1171
|
},
|
|
1157
1172
|
index
|
|
1158
1173
|
);
|
|
1174
|
+
} else if (message.isImageMessage && message.isImageMessage()) {
|
|
1175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1176
|
+
RenderImageMessage2,
|
|
1177
|
+
{
|
|
1178
|
+
message,
|
|
1179
|
+
inProgress,
|
|
1180
|
+
index,
|
|
1181
|
+
isCurrentMessage,
|
|
1182
|
+
AssistantMessage: AssistantMessage2,
|
|
1183
|
+
UserMessage: UserMessage2,
|
|
1184
|
+
onRegenerate,
|
|
1185
|
+
onCopy,
|
|
1186
|
+
onThumbsUp,
|
|
1187
|
+
onThumbsDown
|
|
1188
|
+
},
|
|
1189
|
+
index
|
|
1190
|
+
);
|
|
1159
1191
|
}
|
|
1160
1192
|
}),
|
|
1161
1193
|
interrupt
|
|
@@ -1398,7 +1430,7 @@ var usePushToTalk = ({
|
|
|
1398
1430
|
// src/components/chat/Input.tsx
|
|
1399
1431
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
1400
1432
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1401
|
-
var Input = ({ inProgress, onSend, isVisible = false, onStop }) => {
|
|
1433
|
+
var Input = ({ inProgress, onSend, isVisible = false, onStop, onUpload }) => {
|
|
1402
1434
|
const context = useChatContext();
|
|
1403
1435
|
const copilotContext = (0, import_react_core6.useCopilotContext)();
|
|
1404
1436
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
@@ -1462,6 +1494,7 @@ var Input = ({ inProgress, onSend, isVisible = false, onStop }) => {
|
|
|
1462
1494
|
}
|
|
1463
1495
|
),
|
|
1464
1496
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
1497
|
+
onUpload && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
|
|
1465
1498
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: { flexGrow: 1 } }),
|
|
1466
1499
|
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1467
1500
|
"button",
|
|
@@ -1489,7 +1522,7 @@ var Input = ({ inProgress, onSend, isVisible = false, onStop }) => {
|
|
|
1489
1522
|
// src/components/chat/messages/UserMessage.tsx
|
|
1490
1523
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1491
1524
|
var UserMessage = (props) => {
|
|
1492
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: props.message });
|
|
1525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: props.subComponent || props.message });
|
|
1493
1526
|
};
|
|
1494
1527
|
|
|
1495
1528
|
// src/components/chat/Markdown.tsx
|
|
@@ -2343,13 +2376,77 @@ function RenderAgentStateMessage(_a) {
|
|
|
2343
2376
|
}
|
|
2344
2377
|
}
|
|
2345
2378
|
|
|
2379
|
+
// src/components/chat/messages/RenderImageMessage.tsx
|
|
2380
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2381
|
+
function RenderImageMessage(_a) {
|
|
2382
|
+
var _b = _a, {
|
|
2383
|
+
UserMessage: UserMessage2 = UserMessage,
|
|
2384
|
+
AssistantMessage: AssistantMessage2 = AssistantMessage
|
|
2385
|
+
} = _b, props = __objRest(_b, [
|
|
2386
|
+
"UserMessage",
|
|
2387
|
+
"AssistantMessage"
|
|
2388
|
+
]);
|
|
2389
|
+
const {
|
|
2390
|
+
message,
|
|
2391
|
+
inProgress,
|
|
2392
|
+
index,
|
|
2393
|
+
isCurrentMessage,
|
|
2394
|
+
onRegenerate,
|
|
2395
|
+
onCopy,
|
|
2396
|
+
onThumbsUp,
|
|
2397
|
+
onThumbsDown
|
|
2398
|
+
} = props;
|
|
2399
|
+
if (message.isImageMessage()) {
|
|
2400
|
+
const imageData = `data:${message.format};base64,${message.bytes}`;
|
|
2401
|
+
const imageComponent = /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "copilotKitImage", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2402
|
+
"img",
|
|
2403
|
+
{
|
|
2404
|
+
src: imageData,
|
|
2405
|
+
alt: "User uploaded image",
|
|
2406
|
+
style: { maxWidth: "100%", maxHeight: "300px", borderRadius: "8px" }
|
|
2407
|
+
}
|
|
2408
|
+
) });
|
|
2409
|
+
if (message.role === "user") {
|
|
2410
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2411
|
+
UserMessage2,
|
|
2412
|
+
{
|
|
2413
|
+
"data-message-role": "user",
|
|
2414
|
+
message: "",
|
|
2415
|
+
rawData: message,
|
|
2416
|
+
subComponent: imageComponent
|
|
2417
|
+
},
|
|
2418
|
+
index
|
|
2419
|
+
);
|
|
2420
|
+
} else if (message.role === "assistant") {
|
|
2421
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2422
|
+
AssistantMessage2,
|
|
2423
|
+
{
|
|
2424
|
+
"data-message-role": "assistant",
|
|
2425
|
+
message: "",
|
|
2426
|
+
rawData: message,
|
|
2427
|
+
subComponent: imageComponent,
|
|
2428
|
+
isLoading: inProgress && isCurrentMessage && !message.bytes,
|
|
2429
|
+
isGenerating: inProgress && isCurrentMessage && !!message.bytes,
|
|
2430
|
+
isCurrentMessage,
|
|
2431
|
+
onRegenerate: () => onRegenerate == null ? void 0 : onRegenerate(message.id),
|
|
2432
|
+
onCopy,
|
|
2433
|
+
onThumbsUp,
|
|
2434
|
+
onThumbsDown
|
|
2435
|
+
},
|
|
2436
|
+
index
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
return null;
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2346
2443
|
// src/components/chat/Suggestion.tsx
|
|
2347
2444
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2348
2445
|
var import_shared2 = require("@copilotkit/shared");
|
|
2349
2446
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
2350
|
-
var
|
|
2447
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2351
2448
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
2352
|
-
return /* @__PURE__ */ (0,
|
|
2449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2353
2450
|
"button",
|
|
2354
2451
|
{
|
|
2355
2452
|
disabled: partial,
|
|
@@ -2359,7 +2456,7 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
2359
2456
|
},
|
|
2360
2457
|
className: className || (partial ? "suggestion loading" : "suggestion"),
|
|
2361
2458
|
"data-test-id": "suggestion",
|
|
2362
|
-
children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0,
|
|
2459
|
+
children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { children: title })
|
|
2363
2460
|
}
|
|
2364
2461
|
);
|
|
2365
2462
|
}
|
|
@@ -2439,7 +2536,87 @@ var import_react_core10 = require("@copilotkit/react-core");
|
|
|
2439
2536
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
2440
2537
|
var import_shared3 = require("@copilotkit/shared");
|
|
2441
2538
|
var import_react_core11 = require("@copilotkit/react-core");
|
|
2442
|
-
|
|
2539
|
+
|
|
2540
|
+
// src/components/chat/ImageUploadQueue.tsx
|
|
2541
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2542
|
+
var ImageUploadQueue = ({
|
|
2543
|
+
images,
|
|
2544
|
+
onRemoveImage,
|
|
2545
|
+
className = ""
|
|
2546
|
+
}) => {
|
|
2547
|
+
if (images.length === 0)
|
|
2548
|
+
return null;
|
|
2549
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2550
|
+
"div",
|
|
2551
|
+
{
|
|
2552
|
+
className: `copilotKitImageUploadQueue ${className}`,
|
|
2553
|
+
style: {
|
|
2554
|
+
display: "flex",
|
|
2555
|
+
flexWrap: "wrap",
|
|
2556
|
+
gap: "8px",
|
|
2557
|
+
margin: "8px",
|
|
2558
|
+
padding: "8px"
|
|
2559
|
+
},
|
|
2560
|
+
children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
|
|
2561
|
+
"div",
|
|
2562
|
+
{
|
|
2563
|
+
className: "copilotKitImageUploadQueueItem",
|
|
2564
|
+
style: {
|
|
2565
|
+
position: "relative",
|
|
2566
|
+
display: "inline-block",
|
|
2567
|
+
width: "60px",
|
|
2568
|
+
height: "60px",
|
|
2569
|
+
borderRadius: "4px",
|
|
2570
|
+
overflow: "hidden"
|
|
2571
|
+
},
|
|
2572
|
+
children: [
|
|
2573
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2574
|
+
"img",
|
|
2575
|
+
{
|
|
2576
|
+
src: `data:${image.contentType};base64,${image.bytes}`,
|
|
2577
|
+
alt: `Selected image ${index + 1}`,
|
|
2578
|
+
style: {
|
|
2579
|
+
width: "100%",
|
|
2580
|
+
height: "100%",
|
|
2581
|
+
objectFit: "cover"
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
),
|
|
2585
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2586
|
+
"button",
|
|
2587
|
+
{
|
|
2588
|
+
onClick: () => onRemoveImage(index),
|
|
2589
|
+
className: "copilotKitImageUploadQueueRemoveButton",
|
|
2590
|
+
style: {
|
|
2591
|
+
position: "absolute",
|
|
2592
|
+
top: "2px",
|
|
2593
|
+
right: "2px",
|
|
2594
|
+
background: "rgba(0,0,0,0.6)",
|
|
2595
|
+
color: "white",
|
|
2596
|
+
border: "none",
|
|
2597
|
+
borderRadius: "50%",
|
|
2598
|
+
width: "18px",
|
|
2599
|
+
height: "18px",
|
|
2600
|
+
display: "flex",
|
|
2601
|
+
alignItems: "center",
|
|
2602
|
+
justifyContent: "center",
|
|
2603
|
+
cursor: "pointer",
|
|
2604
|
+
fontSize: "10px",
|
|
2605
|
+
padding: 0
|
|
2606
|
+
},
|
|
2607
|
+
children: "\u2715"
|
|
2608
|
+
}
|
|
2609
|
+
)
|
|
2610
|
+
]
|
|
2611
|
+
},
|
|
2612
|
+
index
|
|
2613
|
+
))
|
|
2614
|
+
}
|
|
2615
|
+
);
|
|
2616
|
+
};
|
|
2617
|
+
|
|
2618
|
+
// src/components/chat/Chat.tsx
|
|
2619
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2443
2620
|
function CopilotChat({
|
|
2444
2621
|
instructions,
|
|
2445
2622
|
onSubmitMessage,
|
|
@@ -2456,14 +2633,64 @@ function CopilotChat({
|
|
|
2456
2633
|
RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
|
|
2457
2634
|
RenderAgentStateMessage: RenderAgentStateMessage2 = RenderAgentStateMessage,
|
|
2458
2635
|
RenderResultMessage: RenderResultMessage2 = RenderResultMessage,
|
|
2636
|
+
RenderImageMessage: RenderImageMessage2 = RenderImageMessage,
|
|
2459
2637
|
Input: Input2 = Input,
|
|
2460
2638
|
className,
|
|
2461
2639
|
icons,
|
|
2462
2640
|
labels,
|
|
2463
2641
|
AssistantMessage: AssistantMessage2 = AssistantMessage,
|
|
2464
|
-
UserMessage: UserMessage2 = UserMessage
|
|
2642
|
+
UserMessage: UserMessage2 = UserMessage,
|
|
2643
|
+
imageUploadsEnabled,
|
|
2644
|
+
inputFileAccept = "image/*"
|
|
2465
2645
|
}) {
|
|
2466
2646
|
const { additionalInstructions, setChatInstructions } = (0, import_react_core10.useCopilotContext)();
|
|
2647
|
+
const [selectedImages, setSelectedImages] = (0, import_react13.useState)([]);
|
|
2648
|
+
const fileInputRef = (0, import_react13.useRef)(null);
|
|
2649
|
+
(0, import_react13.useEffect)(() => {
|
|
2650
|
+
if (!imageUploadsEnabled)
|
|
2651
|
+
return;
|
|
2652
|
+
const handlePaste = (e) => __async(this, null, function* () {
|
|
2653
|
+
var _a, _b;
|
|
2654
|
+
const target = e.target;
|
|
2655
|
+
if (!((_a = target.parentElement) == null ? void 0 : _a.classList.contains("copilotKitInput")))
|
|
2656
|
+
return;
|
|
2657
|
+
const items = Array.from(((_b = e.clipboardData) == null ? void 0 : _b.items) || []);
|
|
2658
|
+
const imageItems = items.filter((item) => item.type.startsWith("image/"));
|
|
2659
|
+
if (imageItems.length === 0)
|
|
2660
|
+
return;
|
|
2661
|
+
e.preventDefault();
|
|
2662
|
+
const imagePromises = imageItems.map((item) => {
|
|
2663
|
+
const file = item.getAsFile();
|
|
2664
|
+
if (!file)
|
|
2665
|
+
return Promise.resolve(null);
|
|
2666
|
+
return new Promise((resolve, reject) => {
|
|
2667
|
+
const reader = new FileReader();
|
|
2668
|
+
reader.onload = (e2) => {
|
|
2669
|
+
var _a2, _b2;
|
|
2670
|
+
const base64String = (_b2 = (_a2 = e2.target) == null ? void 0 : _a2.result) == null ? void 0 : _b2.split(",")[1];
|
|
2671
|
+
if (base64String) {
|
|
2672
|
+
resolve({
|
|
2673
|
+
contentType: file.type,
|
|
2674
|
+
bytes: base64String
|
|
2675
|
+
});
|
|
2676
|
+
} else {
|
|
2677
|
+
resolve(null);
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2680
|
+
reader.onerror = reject;
|
|
2681
|
+
reader.readAsDataURL(file);
|
|
2682
|
+
});
|
|
2683
|
+
});
|
|
2684
|
+
try {
|
|
2685
|
+
const loadedImages = (yield Promise.all(imagePromises)).filter((img) => img !== null);
|
|
2686
|
+
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2687
|
+
} catch (error) {
|
|
2688
|
+
console.error("Error processing pasted images:", error);
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
document.addEventListener("paste", handlePaste);
|
|
2692
|
+
return () => document.removeEventListener("paste", handlePaste);
|
|
2693
|
+
}, [imageUploadsEnabled]);
|
|
2467
2694
|
(0, import_react13.useEffect)(() => {
|
|
2468
2695
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2469
2696
|
setChatInstructions(instructions || "");
|
|
@@ -2491,6 +2718,14 @@ function CopilotChat({
|
|
|
2491
2718
|
onStopGeneration,
|
|
2492
2719
|
onReloadMessages
|
|
2493
2720
|
);
|
|
2721
|
+
const handleSendMessage = (text) => {
|
|
2722
|
+
const images = selectedImages;
|
|
2723
|
+
setSelectedImages([]);
|
|
2724
|
+
if (fileInputRef.current) {
|
|
2725
|
+
fileInputRef.current.value = "";
|
|
2726
|
+
}
|
|
2727
|
+
return sendMessage(text, images);
|
|
2728
|
+
};
|
|
2494
2729
|
const chatContext = import_react13.default.useContext(ChatContext);
|
|
2495
2730
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2496
2731
|
const handleRegenerate = (messageId) => {
|
|
@@ -2504,8 +2739,42 @@ function CopilotChat({
|
|
|
2504
2739
|
onCopy(message);
|
|
2505
2740
|
}
|
|
2506
2741
|
};
|
|
2507
|
-
|
|
2508
|
-
|
|
2742
|
+
const handleImageUpload = (event) => __async(this, null, function* () {
|
|
2743
|
+
if (!event.target.files || event.target.files.length === 0) {
|
|
2744
|
+
return;
|
|
2745
|
+
}
|
|
2746
|
+
const files = Array.from(event.target.files).filter((file) => file.type.startsWith("image/"));
|
|
2747
|
+
if (files.length === 0)
|
|
2748
|
+
return;
|
|
2749
|
+
const fileReadPromises = files.map((file) => {
|
|
2750
|
+
return new Promise((resolve, reject) => {
|
|
2751
|
+
const reader = new FileReader();
|
|
2752
|
+
reader.onload = (e) => {
|
|
2753
|
+
var _a, _b;
|
|
2754
|
+
const base64String = ((_b = (_a = e.target) == null ? void 0 : _a.result) == null ? void 0 : _b.split(",")[1]) || "";
|
|
2755
|
+
if (base64String) {
|
|
2756
|
+
resolve({
|
|
2757
|
+
contentType: file.type,
|
|
2758
|
+
bytes: base64String
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
};
|
|
2762
|
+
reader.onerror = reject;
|
|
2763
|
+
reader.readAsDataURL(file);
|
|
2764
|
+
});
|
|
2765
|
+
});
|
|
2766
|
+
try {
|
|
2767
|
+
const loadedImages = yield Promise.all(fileReadPromises);
|
|
2768
|
+
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2769
|
+
} catch (error) {
|
|
2770
|
+
console.error("Error reading files:", error);
|
|
2771
|
+
}
|
|
2772
|
+
});
|
|
2773
|
+
const removeSelectedImage = (index) => {
|
|
2774
|
+
setSelectedImages((prev) => prev.filter((_, i) => i !== index));
|
|
2775
|
+
};
|
|
2776
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2777
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2509
2778
|
Messages2,
|
|
2510
2779
|
{
|
|
2511
2780
|
AssistantMessage: AssistantMessage2,
|
|
@@ -2514,32 +2783,51 @@ function CopilotChat({
|
|
|
2514
2783
|
RenderActionExecutionMessage: RenderActionExecutionMessage2,
|
|
2515
2784
|
RenderAgentStateMessage: RenderAgentStateMessage2,
|
|
2516
2785
|
RenderResultMessage: RenderResultMessage2,
|
|
2786
|
+
RenderImageMessage: RenderImageMessage2,
|
|
2517
2787
|
messages: visibleMessages,
|
|
2518
2788
|
inProgress: isLoading,
|
|
2519
2789
|
onRegenerate: handleRegenerate,
|
|
2520
2790
|
onCopy: handleCopy,
|
|
2521
2791
|
onThumbsUp,
|
|
2522
2792
|
onThumbsDown,
|
|
2523
|
-
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0,
|
|
2793
|
+
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2524
2794
|
Suggestion,
|
|
2525
2795
|
{
|
|
2526
2796
|
title: suggestion.title,
|
|
2527
2797
|
message: suggestion.message,
|
|
2528
2798
|
partial: suggestion.partial,
|
|
2529
2799
|
className: suggestion.className,
|
|
2530
|
-
onClick: (message) =>
|
|
2800
|
+
onClick: (message) => handleSendMessage(message)
|
|
2531
2801
|
},
|
|
2532
2802
|
index
|
|
2533
2803
|
)) })
|
|
2534
2804
|
}
|
|
2535
2805
|
),
|
|
2536
|
-
/* @__PURE__ */ (0,
|
|
2806
|
+
imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
|
|
2807
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
|
|
2808
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2809
|
+
"input",
|
|
2810
|
+
{
|
|
2811
|
+
type: "file",
|
|
2812
|
+
multiple: true,
|
|
2813
|
+
ref: fileInputRef,
|
|
2814
|
+
onChange: handleImageUpload,
|
|
2815
|
+
accept: inputFileAccept,
|
|
2816
|
+
style: { display: "none" }
|
|
2817
|
+
}
|
|
2818
|
+
)
|
|
2819
|
+
] }),
|
|
2820
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2537
2821
|
Input2,
|
|
2538
2822
|
{
|
|
2539
2823
|
inProgress: isLoading,
|
|
2540
|
-
onSend:
|
|
2824
|
+
onSend: handleSendMessage,
|
|
2541
2825
|
isVisible,
|
|
2542
|
-
onStop: stopGeneration
|
|
2826
|
+
onStop: stopGeneration,
|
|
2827
|
+
onUpload: imageUploadsEnabled ? () => {
|
|
2828
|
+
var _a;
|
|
2829
|
+
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
2830
|
+
} : void 0
|
|
2543
2831
|
}
|
|
2544
2832
|
)
|
|
2545
2833
|
] });
|
|
@@ -2552,10 +2840,10 @@ function WrappedCopilotChat({
|
|
|
2552
2840
|
}) {
|
|
2553
2841
|
const chatContext = import_react13.default.useContext(ChatContext);
|
|
2554
2842
|
if (!chatContext) {
|
|
2555
|
-
return /* @__PURE__ */ (0,
|
|
2556
|
-
}, children: /* @__PURE__ */ (0,
|
|
2843
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2844
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className}`, children }) });
|
|
2557
2845
|
}
|
|
2558
|
-
return /* @__PURE__ */ (0,
|
|
2846
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children });
|
|
2559
2847
|
}
|
|
2560
2848
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
2561
2849
|
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
|
|
@@ -2609,22 +2897,45 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
|
|
|
2609
2897
|
// global context
|
|
2610
2898
|
visibleMessages.length == 0
|
|
2611
2899
|
]);
|
|
2612
|
-
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
2900
|
+
const sendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
|
|
2901
|
+
const images = imagesToUse || [];
|
|
2613
2902
|
abortSuggestions();
|
|
2614
2903
|
setCurrentSuggestions([]);
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2904
|
+
let firstMessage = null;
|
|
2905
|
+
if (messageContent.trim().length > 0) {
|
|
2906
|
+
const textMessage = new import_runtime_client_gql4.TextMessage({
|
|
2907
|
+
content: messageContent,
|
|
2908
|
+
role: import_runtime_client_gql4.Role.User
|
|
2909
|
+
});
|
|
2910
|
+
if (onSubmitMessage) {
|
|
2911
|
+
try {
|
|
2912
|
+
yield onSubmitMessage(messageContent);
|
|
2913
|
+
} catch (error) {
|
|
2914
|
+
console.error("Error in onSubmitMessage:", error);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
yield appendMessage(textMessage, { followUp: images.length === 0 });
|
|
2918
|
+
if (!firstMessage) {
|
|
2919
|
+
firstMessage = textMessage;
|
|
2624
2920
|
}
|
|
2625
2921
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2922
|
+
if (images.length > 0) {
|
|
2923
|
+
for (let i = 0; i < images.length; i++) {
|
|
2924
|
+
const imageMessage = new import_runtime_client_gql4.ImageMessage({
|
|
2925
|
+
format: images[i].contentType.replace("image/", ""),
|
|
2926
|
+
bytes: images[i].bytes,
|
|
2927
|
+
role: import_runtime_client_gql4.Role.User
|
|
2928
|
+
});
|
|
2929
|
+
yield appendMessage(imageMessage, { followUp: i === images.length - 1 });
|
|
2930
|
+
if (!firstMessage) {
|
|
2931
|
+
firstMessage = imageMessage;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
if (!firstMessage) {
|
|
2936
|
+
return new import_runtime_client_gql4.TextMessage({ content: "", role: import_runtime_client_gql4.Role.User });
|
|
2937
|
+
}
|
|
2938
|
+
return firstMessage;
|
|
2628
2939
|
});
|
|
2629
2940
|
const messages = visibleMessages;
|
|
2630
2941
|
const { setMessages } = messagesContext;
|
|
@@ -2717,7 +3028,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
|
|
|
2717
3028
|
};
|
|
2718
3029
|
|
|
2719
3030
|
// src/components/chat/Modal.tsx
|
|
2720
|
-
var
|
|
3031
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2721
3032
|
var CopilotModal = ({
|
|
2722
3033
|
instructions,
|
|
2723
3034
|
defaultOpen = false,
|
|
@@ -2751,19 +3062,19 @@ var CopilotModal = ({
|
|
|
2751
3062
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2752
3063
|
setOpenState(open);
|
|
2753
3064
|
};
|
|
2754
|
-
return /* @__PURE__ */ (0,
|
|
3065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
|
|
2755
3066
|
children,
|
|
2756
|
-
/* @__PURE__ */ (0,
|
|
2757
|
-
/* @__PURE__ */ (0,
|
|
2758
|
-
/* @__PURE__ */ (0,
|
|
3067
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
3068
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Button2, {}),
|
|
3069
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
2759
3070
|
Window2,
|
|
2760
3071
|
{
|
|
2761
3072
|
clickOutsideToClose,
|
|
2762
3073
|
shortcut,
|
|
2763
3074
|
hitEscapeToClose,
|
|
2764
3075
|
children: [
|
|
2765
|
-
/* @__PURE__ */ (0,
|
|
2766
|
-
/* @__PURE__ */ (0,
|
|
3076
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}),
|
|
3077
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2767
3078
|
CopilotChat,
|
|
2768
3079
|
{
|
|
2769
3080
|
instructions,
|