@copilotkit/react-ui 1.10.0-next.8 → 1.10.0-next.9
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 +14 -0
- package/dist/{chunk-3DVMCBME.mjs → chunk-2KG77MAY.mjs} +61 -8
- package/dist/chunk-2KG77MAY.mjs.map +1 -0
- package/dist/{chunk-APLX7E54.mjs → chunk-6C3YVF5W.mjs} +2 -2
- package/dist/{chunk-BPU3FDT4.mjs → chunk-7K2X77PW.mjs} +24 -5
- package/dist/chunk-7K2X77PW.mjs.map +1 -0
- package/dist/{chunk-KLV4ERV6.mjs → chunk-TW4LLLTE.mjs} +2 -2
- package/dist/components/chat/Chat.d.ts +12 -1
- package/dist/components/chat/Chat.js +60 -7
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +1 -1
- package/dist/components/chat/Modal.js +76 -10
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +2 -2
- package/dist/components/chat/Popup.js +76 -10
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +3 -3
- package/dist/components/chat/Sidebar.js +76 -10
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +3 -3
- package/dist/components/chat/index.js +76 -10
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +4 -4
- package/dist/components/chat/props.d.ts +6 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.js +76 -10
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/index.js +78 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +94 -7
- package/src/components/chat/Modal.tsx +24 -3
- package/src/components/chat/props.ts +7 -1
- package/dist/chunk-3DVMCBME.mjs.map +0 -1
- package/dist/chunk-BPU3FDT4.mjs.map +0 -1
- /package/dist/{chunk-APLX7E54.mjs.map → chunk-6C3YVF5W.mjs.map} +0 -0
- /package/dist/{chunk-KLV4ERV6.mjs.map → chunk-TW4LLLTE.mjs.map} +0 -0
|
@@ -2313,17 +2313,20 @@ function CopilotChat({
|
|
|
2313
2313
|
imageUploadsEnabled,
|
|
2314
2314
|
inputFileAccept = "image/*",
|
|
2315
2315
|
hideStopButton,
|
|
2316
|
-
observabilityHooks
|
|
2316
|
+
observabilityHooks,
|
|
2317
|
+
renderError
|
|
2317
2318
|
}) {
|
|
2318
2319
|
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
|
|
2320
|
+
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2319
2321
|
const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
|
|
2322
|
+
const [chatError, setChatError] = (0, import_react14.useState)(null);
|
|
2320
2323
|
const fileInputRef = (0, import_react14.useRef)(null);
|
|
2321
2324
|
const triggerObservabilityHook = (0, import_react14.useCallback)(
|
|
2322
2325
|
(hookName, ...args) => {
|
|
2323
|
-
if (
|
|
2326
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2324
2327
|
observabilityHooks[hookName](...args);
|
|
2325
2328
|
}
|
|
2326
|
-
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !
|
|
2329
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
|
|
2327
2330
|
setBannerError(
|
|
2328
2331
|
new import_shared3.CopilotKitError({
|
|
2329
2332
|
message: "observabilityHooks requires a publicApiKey to function.",
|
|
@@ -2335,7 +2338,50 @@ function CopilotChat({
|
|
|
2335
2338
|
import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2336
2339
|
}
|
|
2337
2340
|
},
|
|
2338
|
-
[
|
|
2341
|
+
[publicApiKey, observabilityHooks, setBannerError]
|
|
2342
|
+
);
|
|
2343
|
+
const triggerChatError = (0, import_react14.useCallback)(
|
|
2344
|
+
(error, operation, originalError) => {
|
|
2345
|
+
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2346
|
+
setChatError({
|
|
2347
|
+
message: errorMessage,
|
|
2348
|
+
operation,
|
|
2349
|
+
timestamp: Date.now()
|
|
2350
|
+
});
|
|
2351
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
|
|
2352
|
+
const errorEvent = {
|
|
2353
|
+
type: "error",
|
|
2354
|
+
timestamp: Date.now(),
|
|
2355
|
+
context: {
|
|
2356
|
+
source: "ui",
|
|
2357
|
+
request: {
|
|
2358
|
+
operation,
|
|
2359
|
+
url: chatApiEndpoint,
|
|
2360
|
+
startTime: Date.now()
|
|
2361
|
+
},
|
|
2362
|
+
technical: {
|
|
2363
|
+
environment: "browser",
|
|
2364
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2365
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2366
|
+
}
|
|
2367
|
+
},
|
|
2368
|
+
error
|
|
2369
|
+
};
|
|
2370
|
+
observabilityHooks.onError(errorEvent);
|
|
2371
|
+
}
|
|
2372
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
|
|
2373
|
+
setBannerError(
|
|
2374
|
+
new import_shared3.CopilotKitError({
|
|
2375
|
+
message: "observabilityHooks.onError requires a publicApiKey to function.",
|
|
2376
|
+
code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2377
|
+
severity: import_shared3.Severity.CRITICAL,
|
|
2378
|
+
visibility: import_shared3.ErrorVisibility.BANNER
|
|
2379
|
+
})
|
|
2380
|
+
);
|
|
2381
|
+
import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks.onError");
|
|
2382
|
+
}
|
|
2383
|
+
},
|
|
2384
|
+
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2339
2385
|
);
|
|
2340
2386
|
(0, import_react14.useEffect)(() => {
|
|
2341
2387
|
if (!imageUploadsEnabled)
|
|
@@ -2376,12 +2422,13 @@ function CopilotChat({
|
|
|
2376
2422
|
const loadedImages = (yield Promise.all(imagePromises)).filter((img) => img !== null);
|
|
2377
2423
|
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2378
2424
|
} catch (error) {
|
|
2425
|
+
triggerChatError(error, "processClipboardImages", error);
|
|
2379
2426
|
console.error("Error processing pasted images:", error);
|
|
2380
2427
|
}
|
|
2381
2428
|
});
|
|
2382
2429
|
document.addEventListener("paste", handlePaste);
|
|
2383
2430
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2384
|
-
}, [imageUploadsEnabled]);
|
|
2431
|
+
}, [imageUploadsEnabled, triggerChatError]);
|
|
2385
2432
|
(0, import_react14.useEffect)(() => {
|
|
2386
2433
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2387
2434
|
setChatInstructions(instructions || "");
|
|
@@ -2472,6 +2519,7 @@ function CopilotChat({
|
|
|
2472
2519
|
const loadedImages = yield Promise.all(fileReadPromises);
|
|
2473
2520
|
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2474
2521
|
} catch (error) {
|
|
2522
|
+
triggerChatError(error, "processUploadedImages", error);
|
|
2475
2523
|
console.error("Error reading files:", error);
|
|
2476
2524
|
}
|
|
2477
2525
|
});
|
|
@@ -2491,6 +2539,12 @@ function CopilotChat({
|
|
|
2491
2539
|
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2492
2540
|
};
|
|
2493
2541
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2542
|
+
chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
|
|
2543
|
+
onDismiss: () => setChatError(null),
|
|
2544
|
+
onRetry: () => {
|
|
2545
|
+
setChatError(null);
|
|
2546
|
+
}
|
|
2547
|
+
})),
|
|
2494
2548
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2495
2549
|
Messages2,
|
|
2496
2550
|
{
|
|
@@ -2724,8 +2778,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2724
2778
|
stableContext,
|
|
2725
2779
|
messagesContext.messages,
|
|
2726
2780
|
appendMessage,
|
|
2727
|
-
runChatCompletion
|
|
2728
|
-
hint
|
|
2781
|
+
runChatCompletion
|
|
2729
2782
|
);
|
|
2730
2783
|
}
|
|
2731
2784
|
});
|
|
@@ -2795,6 +2848,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2795
2848
|
|
|
2796
2849
|
// src/components/chat/Modal.tsx
|
|
2797
2850
|
var import_react_core11 = require("@copilotkit/react-core");
|
|
2851
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
2798
2852
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2799
2853
|
var CopilotModalInner = (_a) => {
|
|
2800
2854
|
var _b = _a, {
|
|
@@ -2820,14 +2874,26 @@ var CopilotModalInner = (_a) => {
|
|
|
2820
2874
|
"Button",
|
|
2821
2875
|
"Header"
|
|
2822
2876
|
]);
|
|
2823
|
-
const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
|
|
2877
|
+
const { copilotApiConfig, setBannerError } = (0, import_react_core11.useCopilotContext)();
|
|
2878
|
+
const { publicApiKey } = copilotApiConfig;
|
|
2824
2879
|
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2825
2880
|
(hookName, ...args) => {
|
|
2826
|
-
if (
|
|
2881
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2827
2882
|
observabilityHooks[hookName](...args);
|
|
2828
2883
|
}
|
|
2884
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
|
|
2885
|
+
setBannerError(
|
|
2886
|
+
new import_shared5.CopilotKitError({
|
|
2887
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
2888
|
+
code: import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2889
|
+
severity: import_shared5.Severity.CRITICAL,
|
|
2890
|
+
visibility: import_shared5.ErrorVisibility.BANNER
|
|
2891
|
+
})
|
|
2892
|
+
);
|
|
2893
|
+
import_shared5.styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2894
|
+
}
|
|
2829
2895
|
},
|
|
2830
|
-
[
|
|
2896
|
+
[publicApiKey, observabilityHooks, setBannerError]
|
|
2831
2897
|
);
|
|
2832
2898
|
const { open } = useChatContext();
|
|
2833
2899
|
const prevOpen = (0, import_react15.useRef)(open);
|