@copilotkit/react-ui 1.10.0-next.4 → 1.10.0-next.5
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 +10 -0
- package/dist/{chunk-WYEGK6BP.mjs → chunk-BXX6RM44.mjs} +2 -2
- package/dist/chunk-BXX6RM44.mjs.map +1 -0
- package/dist/chunk-BY42E5VF.mjs +203 -0
- package/dist/chunk-BY42E5VF.mjs.map +1 -0
- package/dist/{chunk-P6O2MZGT.mjs → chunk-K344MVUT.mjs} +58 -5
- package/dist/chunk-K344MVUT.mjs.map +1 -0
- package/dist/{chunk-2TABXABK.mjs → chunk-MYWIJSW6.mjs} +2 -2
- package/dist/chunk-MYWIJSW6.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +10 -5
- package/dist/components/chat/Chat.js +54 -7
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +1 -1
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +157 -52
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +2 -2
- package/dist/components/chat/Popup.js +157 -52
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +3 -3
- package/dist/components/chat/Sidebar.js +157 -52
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +3 -3
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +157 -52
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +4 -4
- package/dist/components/chat/props.d.ts +39 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +157 -52
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +161 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +98 -4
- package/src/components/chat/Modal.tsx +107 -41
- package/src/components/chat/Popup.tsx +20 -0
- package/src/components/chat/Sidebar.tsx +22 -0
- package/src/components/chat/props.ts +46 -0
- package/dist/chunk-2TABXABK.mjs.map +0 -1
- package/dist/chunk-P6O2MZGT.mjs.map +0 -1
- package/dist/chunk-QKDRZ7WA.mjs +0 -144
- package/dist/chunk-QKDRZ7WA.mjs.map +0 -1
- package/dist/chunk-WYEGK6BP.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-BY42E5VF.mjs";
|
|
4
4
|
import "../../chunk-C3GSYRC3.mjs";
|
|
5
5
|
import "../../chunk-GDSZGYCE.mjs";
|
|
6
6
|
import "../../chunk-V7W6IM2V.mjs";
|
|
@@ -11,7 +11,7 @@ import "../../chunk-KXE2JCUH.mjs";
|
|
|
11
11
|
import "../../chunk-NRA3CFEE.mjs";
|
|
12
12
|
import "../../chunk-BH6PCAAL.mjs";
|
|
13
13
|
import "../../chunk-UFN2VWSR.mjs";
|
|
14
|
-
import "../../chunk-
|
|
14
|
+
import "../../chunk-K344MVUT.mjs";
|
|
15
15
|
import "../../chunk-JHUTTP5C.mjs";
|
|
16
16
|
import "../../chunk-GCKKSSBU.mjs";
|
|
17
17
|
import "../../chunk-DBKRAOH7.mjs";
|
|
@@ -2168,6 +2168,7 @@ function RenderMessage(_a) {
|
|
|
2168
2168
|
var import_react14 = __toESM(require("react"));
|
|
2169
2169
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2170
2170
|
var import_shared3 = require("@copilotkit/shared");
|
|
2171
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
2171
2172
|
var import_react_core10 = require("@copilotkit/react-core");
|
|
2172
2173
|
|
|
2173
2174
|
// src/components/chat/ImageUploadQueue.tsx
|
|
@@ -2313,11 +2314,31 @@ function CopilotChat({
|
|
|
2313
2314
|
ImageRenderer: ImageRenderer2 = ImageRenderer,
|
|
2314
2315
|
imageUploadsEnabled,
|
|
2315
2316
|
inputFileAccept = "image/*",
|
|
2316
|
-
hideStopButton
|
|
2317
|
+
hideStopButton,
|
|
2318
|
+
observabilityHooks
|
|
2317
2319
|
}) {
|
|
2318
|
-
const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
|
|
2320
|
+
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
|
|
2319
2321
|
const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
|
|
2320
2322
|
const fileInputRef = (0, import_react14.useRef)(null);
|
|
2323
|
+
const triggerObservabilityHook = (0, import_react14.useCallback)(
|
|
2324
|
+
(hookName, ...args) => {
|
|
2325
|
+
if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2326
|
+
observabilityHooks[hookName](...args);
|
|
2327
|
+
}
|
|
2328
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
|
|
2329
|
+
setBannerError(
|
|
2330
|
+
new import_shared3.CopilotKitError({
|
|
2331
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
2332
|
+
code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2333
|
+
severity: import_shared3.Severity.CRITICAL,
|
|
2334
|
+
visibility: import_shared3.ErrorVisibility.BANNER
|
|
2335
|
+
})
|
|
2336
|
+
);
|
|
2337
|
+
import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2338
|
+
}
|
|
2339
|
+
},
|
|
2340
|
+
[copilotApiConfig.publicApiKey, observabilityHooks]
|
|
2341
|
+
);
|
|
2321
2342
|
(0, import_react14.useEffect)(() => {
|
|
2322
2343
|
if (!imageUploadsEnabled)
|
|
2323
2344
|
return;
|
|
@@ -2390,12 +2411,24 @@ function CopilotChat({
|
|
|
2390
2411
|
onStopGeneration,
|
|
2391
2412
|
onReloadMessages
|
|
2392
2413
|
);
|
|
2414
|
+
const prevIsLoading = (0, import_react14.useRef)(isLoading);
|
|
2415
|
+
(0, import_react14.useEffect)(() => {
|
|
2416
|
+
if (prevIsLoading.current !== isLoading) {
|
|
2417
|
+
if (isLoading) {
|
|
2418
|
+
triggerObservabilityHook("onChatStarted");
|
|
2419
|
+
} else {
|
|
2420
|
+
triggerObservabilityHook("onChatStopped");
|
|
2421
|
+
}
|
|
2422
|
+
prevIsLoading.current = isLoading;
|
|
2423
|
+
}
|
|
2424
|
+
}, [isLoading, triggerObservabilityHook]);
|
|
2393
2425
|
const handleSendMessage = (text) => {
|
|
2394
2426
|
const images = selectedImages;
|
|
2395
2427
|
setSelectedImages([]);
|
|
2396
2428
|
if (fileInputRef.current) {
|
|
2397
2429
|
fileInputRef.current.value = "";
|
|
2398
2430
|
}
|
|
2431
|
+
triggerObservabilityHook("onMessageSent", text);
|
|
2399
2432
|
return sendMessage(text, images);
|
|
2400
2433
|
};
|
|
2401
2434
|
const chatContext = import_react14.default.useContext(ChatContext);
|
|
@@ -2404,12 +2437,14 @@ function CopilotChat({
|
|
|
2404
2437
|
if (onRegenerate) {
|
|
2405
2438
|
onRegenerate(messageId);
|
|
2406
2439
|
}
|
|
2440
|
+
triggerObservabilityHook("onMessageRegenerated", messageId);
|
|
2407
2441
|
reloadMessages(messageId);
|
|
2408
2442
|
};
|
|
2409
2443
|
const handleCopy = (message) => {
|
|
2410
2444
|
if (onCopy) {
|
|
2411
2445
|
onCopy(message);
|
|
2412
2446
|
}
|
|
2447
|
+
triggerObservabilityHook("onMessageCopied", message);
|
|
2413
2448
|
};
|
|
2414
2449
|
const handleImageUpload = (event) => __async(this, null, function* () {
|
|
2415
2450
|
if (!event.target.files || event.target.files.length === 0) {
|
|
@@ -2445,6 +2480,18 @@ function CopilotChat({
|
|
|
2445
2480
|
const removeSelectedImage = (index) => {
|
|
2446
2481
|
setSelectedImages((prev) => prev.filter((_, i) => i !== index));
|
|
2447
2482
|
};
|
|
2483
|
+
const handleThumbsUp = (message) => {
|
|
2484
|
+
if (onThumbsUp) {
|
|
2485
|
+
onThumbsUp(message);
|
|
2486
|
+
}
|
|
2487
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
|
|
2488
|
+
};
|
|
2489
|
+
const handleThumbsDown = (message) => {
|
|
2490
|
+
if (onThumbsDown) {
|
|
2491
|
+
onThumbsDown(message);
|
|
2492
|
+
}
|
|
2493
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2494
|
+
};
|
|
2448
2495
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2449
2496
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2450
2497
|
Messages2,
|
|
@@ -2456,8 +2503,8 @@ function CopilotChat({
|
|
|
2456
2503
|
inProgress: isLoading,
|
|
2457
2504
|
onRegenerate: handleRegenerate,
|
|
2458
2505
|
onCopy: handleCopy,
|
|
2459
|
-
onThumbsUp,
|
|
2460
|
-
onThumbsDown,
|
|
2506
|
+
onThumbsUp: handleThumbsUp,
|
|
2507
|
+
onThumbsDown: handleThumbsDown,
|
|
2461
2508
|
markdownTagRenderers,
|
|
2462
2509
|
ImageRenderer: ImageRenderer2,
|
|
2463
2510
|
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
@@ -2613,7 +2660,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2613
2660
|
let firstMessage = null;
|
|
2614
2661
|
if (messageContent.trim().length > 0) {
|
|
2615
2662
|
const textMessage = {
|
|
2616
|
-
id: (0,
|
|
2663
|
+
id: (0, import_shared4.randomId)(),
|
|
2617
2664
|
role: "user",
|
|
2618
2665
|
content: messageContent
|
|
2619
2666
|
};
|
|
@@ -2635,7 +2682,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2635
2682
|
if (images.length > 0) {
|
|
2636
2683
|
for (let i = 0; i < images.length; i++) {
|
|
2637
2684
|
const imageMessage = {
|
|
2638
|
-
id: (0,
|
|
2685
|
+
id: (0, import_shared4.randomId)(),
|
|
2639
2686
|
role: "user",
|
|
2640
2687
|
image: {
|
|
2641
2688
|
format: images[i].contentType.replace("image/", ""),
|
|
@@ -2649,7 +2696,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2649
2696
|
}
|
|
2650
2697
|
}
|
|
2651
2698
|
if (!firstMessage) {
|
|
2652
|
-
return { role: "user", content: "", id: (0,
|
|
2699
|
+
return { role: "user", content: "", id: (0, import_shared4.randomId)() };
|
|
2653
2700
|
}
|
|
2654
2701
|
return firstMessage;
|
|
2655
2702
|
});
|
|
@@ -2748,7 +2795,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2748
2795
|
};
|
|
2749
2796
|
|
|
2750
2797
|
// src/components/chat/Modal.tsx
|
|
2798
|
+
var import_react_core11 = require("@copilotkit/react-core");
|
|
2751
2799
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2800
|
+
var CopilotModalInner = (_a) => {
|
|
2801
|
+
var _b = _a, {
|
|
2802
|
+
observabilityHooks,
|
|
2803
|
+
onSetOpen,
|
|
2804
|
+
clickOutsideToClose,
|
|
2805
|
+
hitEscapeToClose,
|
|
2806
|
+
shortcut,
|
|
2807
|
+
className,
|
|
2808
|
+
children,
|
|
2809
|
+
Window: Window2,
|
|
2810
|
+
Button: Button2,
|
|
2811
|
+
Header: Header2
|
|
2812
|
+
} = _b, chatProps = __objRest(_b, [
|
|
2813
|
+
"observabilityHooks",
|
|
2814
|
+
"onSetOpen",
|
|
2815
|
+
"clickOutsideToClose",
|
|
2816
|
+
"hitEscapeToClose",
|
|
2817
|
+
"shortcut",
|
|
2818
|
+
"className",
|
|
2819
|
+
"children",
|
|
2820
|
+
"Window",
|
|
2821
|
+
"Button",
|
|
2822
|
+
"Header"
|
|
2823
|
+
]);
|
|
2824
|
+
const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
|
|
2825
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2826
|
+
(hookName, ...args) => {
|
|
2827
|
+
if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2828
|
+
observabilityHooks[hookName](...args);
|
|
2829
|
+
}
|
|
2830
|
+
},
|
|
2831
|
+
[copilotApiConfig.publicApiKey, observabilityHooks]
|
|
2832
|
+
);
|
|
2833
|
+
const { open } = useChatContext();
|
|
2834
|
+
const prevOpen = (0, import_react15.useRef)(open);
|
|
2835
|
+
(0, import_react15.useEffect)(() => {
|
|
2836
|
+
if (prevOpen.current !== open) {
|
|
2837
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2838
|
+
if (open) {
|
|
2839
|
+
triggerObservabilityHook("onChatExpanded");
|
|
2840
|
+
} else {
|
|
2841
|
+
triggerObservabilityHook("onChatMinimized");
|
|
2842
|
+
}
|
|
2843
|
+
prevOpen.current = open;
|
|
2844
|
+
}
|
|
2845
|
+
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2846
|
+
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
|
|
2847
|
+
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
2848
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
|
|
2849
|
+
memoizedChildren,
|
|
2850
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
|
|
2851
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
|
|
2852
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
2853
|
+
Window2,
|
|
2854
|
+
{
|
|
2855
|
+
clickOutsideToClose,
|
|
2856
|
+
shortcut,
|
|
2857
|
+
hitEscapeToClose,
|
|
2858
|
+
children: [
|
|
2859
|
+
memoizedHeader,
|
|
2860
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
|
|
2861
|
+
]
|
|
2862
|
+
}
|
|
2863
|
+
)
|
|
2864
|
+
] })
|
|
2865
|
+
] });
|
|
2866
|
+
};
|
|
2752
2867
|
var CopilotModal = (_a) => {
|
|
2753
2868
|
var _b = _a, {
|
|
2754
2869
|
instructions,
|
|
@@ -2777,7 +2892,8 @@ var CopilotModal = (_a) => {
|
|
|
2777
2892
|
onRegenerate,
|
|
2778
2893
|
markdownTagRenderers,
|
|
2779
2894
|
className,
|
|
2780
|
-
children
|
|
2895
|
+
children,
|
|
2896
|
+
observabilityHooks
|
|
2781
2897
|
} = _b, props = __objRest(_b, [
|
|
2782
2898
|
"instructions",
|
|
2783
2899
|
"defaultOpen",
|
|
@@ -2805,52 +2921,41 @@ var CopilotModal = (_a) => {
|
|
|
2805
2921
|
"onRegenerate",
|
|
2806
2922
|
"markdownTagRenderers",
|
|
2807
2923
|
"className",
|
|
2808
|
-
"children"
|
|
2924
|
+
"children",
|
|
2925
|
+
"observabilityHooks"
|
|
2809
2926
|
]);
|
|
2810
2927
|
const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
onThumbsUp,
|
|
2843
|
-
onThumbsDown,
|
|
2844
|
-
onCopy,
|
|
2845
|
-
onRegenerate,
|
|
2846
|
-
markdownTagRenderers
|
|
2847
|
-
})
|
|
2848
|
-
)
|
|
2849
|
-
]
|
|
2850
|
-
}
|
|
2851
|
-
)
|
|
2852
|
-
] })
|
|
2853
|
-
] });
|
|
2928
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2929
|
+
CopilotModalInner,
|
|
2930
|
+
__spreadProps(__spreadValues({
|
|
2931
|
+
observabilityHooks,
|
|
2932
|
+
onSetOpen,
|
|
2933
|
+
clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
|
|
2934
|
+
hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
|
|
2935
|
+
shortcut: shortcut != null ? shortcut : "/",
|
|
2936
|
+
className,
|
|
2937
|
+
Window: Window2,
|
|
2938
|
+
Button: Button2,
|
|
2939
|
+
Header: Header2,
|
|
2940
|
+
instructions,
|
|
2941
|
+
onSubmitMessage,
|
|
2942
|
+
onStopGeneration,
|
|
2943
|
+
onReloadMessages,
|
|
2944
|
+
makeSystemMessage,
|
|
2945
|
+
onInProgress,
|
|
2946
|
+
Messages: Messages2,
|
|
2947
|
+
Input: Input2,
|
|
2948
|
+
AssistantMessage: AssistantMessage2,
|
|
2949
|
+
UserMessage: UserMessage2,
|
|
2950
|
+
onThumbsUp,
|
|
2951
|
+
onThumbsDown,
|
|
2952
|
+
onCopy,
|
|
2953
|
+
onRegenerate,
|
|
2954
|
+
markdownTagRenderers
|
|
2955
|
+
}, props), {
|
|
2956
|
+
children
|
|
2957
|
+
})
|
|
2958
|
+
) });
|
|
2854
2959
|
};
|
|
2855
2960
|
|
|
2856
2961
|
// src/components/chat/Popup.tsx
|