@copilotkit/react-core 1.56.4-canary.1777531098 → 1.56.4-canary.1777629975

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.
@@ -45,8 +45,8 @@ let zod = require("zod");
45
45
  let _lit_labs_react = require("@lit-labs/react");
46
46
  let _copilotkit_a2ui_renderer = require("@copilotkit/a2ui-renderer");
47
47
  let zod_to_json_schema = require("zod-to-json-schema");
48
- let react_dom = require("react-dom");
49
48
  let _tanstack_react_virtual = require("@tanstack/react-virtual");
49
+ let react_dom = require("react-dom");
50
50
  let use_stick_to_bottom = require("use-stick-to-bottom");
51
51
  let react_markdown = require("react-markdown");
52
52
  react_markdown = __toESM(react_markdown);
@@ -4332,19 +4332,15 @@ function useConfigureSuggestions(config, deps) {
4332
4332
  return consumer;
4333
4333
  }, [normalizedConfig, resolvedConsumerAgentId]);
4334
4334
  const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
4335
- const isDynamicConfigType = (0, react.useMemo)(() => !!normalizedConfig && "instructions" in normalizedConfig, [normalizedConfig]);
4336
4335
  const requestReload = (0, react.useCallback)(() => {
4337
4336
  if (!normalizedConfig) return;
4338
4337
  if (isGlobalConfig) {
4339
- const seen = /* @__PURE__ */ new Set();
4340
4338
  const agents = Object.values(copilotkit.agents ?? {});
4341
4339
  for (const entry of agents) {
4342
4340
  const agentId = entry.agentId;
4343
4341
  if (!agentId) continue;
4344
- seen.add(agentId);
4345
4342
  if (!entry.isRunning) copilotkit.reloadSuggestions(agentId);
4346
4343
  }
4347
- if (targetAgentId && !seen.has(targetAgentId)) copilotkit.reloadSuggestions(targetAgentId);
4348
4344
  return;
4349
4345
  }
4350
4346
  if (!targetAgentId) return;
@@ -4389,26 +4385,6 @@ function useConfigureSuggestions(config, deps) {
4389
4385
  requestReload,
4390
4386
  ...extraDeps
4391
4387
  ]);
4392
- (0, react.useEffect)(() => {
4393
- if (!normalizedConfig || !isDynamicConfigType) return;
4394
- if (!targetAgentId) return;
4395
- if (!!copilotkit.getAgent(targetAgentId)) return;
4396
- const subscription = copilotkit.subscribe({ onAgentsChanged: () => {
4397
- if (copilotkit.getAgent(targetAgentId)) {
4398
- requestReload();
4399
- subscription.unsubscribe();
4400
- }
4401
- } });
4402
- return () => {
4403
- subscription.unsubscribe();
4404
- };
4405
- }, [
4406
- copilotkit,
4407
- normalizedConfig,
4408
- isDynamicConfigType,
4409
- targetAgentId,
4410
- requestReload
4411
- ]);
4412
4388
  }
4413
4389
  function isDynamicConfig(config) {
4414
4390
  return "instructions" in config;
@@ -5060,101 +5036,20 @@ CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantM
5060
5036
  CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
5061
5037
  var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
5062
5038
 
5063
- //#endregion
5064
- //#region src/v2/components/chat/Lightbox.tsx
5065
- function Lightbox({ onClose, children }) {
5066
- (0, react.useEffect)(() => {
5067
- const handleKey = (e) => {
5068
- if (e.key === "Escape") onClose();
5069
- };
5070
- document.addEventListener("keydown", handleKey);
5071
- return () => document.removeEventListener("keydown", handleKey);
5072
- }, [onClose]);
5073
- if (typeof document === "undefined") return null;
5074
- return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5075
- className: "cpk:fixed cpk:inset-0 cpk:z-[9999] cpk:flex cpk:items-center cpk:justify-center cpk:bg-black/80 cpk:animate-fade-in",
5076
- onClick: onClose,
5077
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
5078
- onClick: onClose,
5079
- className: "cpk:absolute cpk:top-4 cpk:right-4 cpk:text-white cpk:bg-white/10 cpk:hover:bg-white/20 cpk:rounded-full cpk:w-10 cpk:h-10 cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer cpk:border-none cpk:z-10",
5080
- "aria-label": "Close preview",
5081
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "cpk:w-5 cpk:h-5" })
5082
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5083
- onClick: (e) => e.stopPropagation(),
5084
- children
5085
- })]
5086
- }), document.body);
5087
- }
5088
- /**
5089
- * Hook that manages lightbox open/close and uses the View Transition API to
5090
- * morph the thumbnail into fullscreen content.
5091
- *
5092
- * The trick: `view-transition-name` must live on exactly ONE element at a time.
5093
- * - Old state (thumbnail visible): name is on the thumbnail.
5094
- * - New state (lightbox visible): name moves to the lightbox content.
5095
- * `flushSync` ensures React commits the DOM change synchronously inside the
5096
- * `startViewTransition` callback so the API can snapshot old → new correctly.
5097
- */
5098
- function useLightbox() {
5099
- const thumbnailRef = (0, react.useRef)(null);
5100
- const [open, setOpen] = (0, react.useState)(false);
5101
- const vtName = (0, react.useId)();
5102
- return {
5103
- thumbnailRef,
5104
- vtName,
5105
- open,
5106
- openLightbox: (0, react.useCallback)(() => {
5107
- const thumb = thumbnailRef.current;
5108
- const doc = document;
5109
- if (doc.startViewTransition && thumb) {
5110
- thumb.style.viewTransitionName = vtName;
5111
- doc.startViewTransition(() => {
5112
- thumb.style.viewTransitionName = "";
5113
- (0, react_dom.flushSync)(() => setOpen(true));
5114
- });
5115
- } else setOpen(true);
5116
- }, [vtName]),
5117
- closeLightbox: (0, react.useCallback)(() => {
5118
- const thumb = thumbnailRef.current;
5119
- const doc = document;
5120
- if (doc.startViewTransition && thumb) doc.startViewTransition(() => {
5121
- (0, react_dom.flushSync)(() => setOpen(false));
5122
- thumb.style.viewTransitionName = vtName;
5123
- }).finished.then(() => {
5124
- thumb.style.viewTransitionName = "";
5125
- }).catch(() => {
5126
- thumb.style.viewTransitionName = "";
5127
- });
5128
- else setOpen(false);
5129
- }, [vtName])
5130
- };
5131
- }
5132
-
5133
5039
  //#endregion
5134
5040
  //#region src/v2/components/chat/CopilotChatAttachmentRenderer.tsx
5135
5041
  const ImageAttachment = (0, react.memo)(function ImageAttachment({ src, className }) {
5136
5042
  const [error, setError] = (0, react.useState)(false);
5137
- const { thumbnailRef, vtName, open, openLightbox, closeLightbox } = useLightbox();
5138
5043
  if (error) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5139
5044
  className: cn("cpk:flex cpk:flex-col cpk:items-center cpk:justify-center cpk:rounded-lg cpk:bg-muted cpk:p-4 cpk:text-sm cpk:text-muted-foreground", className),
5140
5045
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Failed to load image" })
5141
5046
  });
5142
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5143
- ref: thumbnailRef,
5047
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5144
5048
  src,
5145
5049
  alt: "Image attachment",
5146
- className: cn("cpk:max-w-[80px] cpk:max-h-[80px] cpk:w-auto cpk:h-auto cpk:rounded-xl cpk:object-cover cpk:cursor-pointer cpk:bg-muted", className),
5147
- onClick: openLightbox,
5050
+ className: cn("cpk:max-w-full cpk:h-auto cpk:rounded-lg", className),
5148
5051
  onError: () => setError(true)
5149
- }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Lightbox, {
5150
- onClose: closeLightbox,
5151
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5152
- style: { viewTransitionName: vtName },
5153
- src,
5154
- alt: "Image attachment",
5155
- className: "cpk:max-w-[90vw] cpk:max-h-[90vh] cpk:object-contain cpk:rounded-lg"
5156
- })
5157
- })] });
5052
+ });
5158
5053
  });
5159
5054
  const AudioAttachment = (0, react.memo)(function AudioAttachment({ src, filename, className }) {
5160
5055
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -5279,15 +5174,15 @@ function CopilotChatUserMessage({ message, onEditMessage, branchIndex, numberOfB
5279
5174
  "data-message-id": message.id,
5280
5175
  ...props,
5281
5176
  children: [
5177
+ BoundMessageRenderer,
5282
5178
  mediaParts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5283
- className: "cpk:flex cpk:flex-row cpk:flex-wrap cpk:justify-end cpk:gap-2 cpk:mb-2",
5179
+ className: "cpk:flex cpk:flex-col cpk:items-end cpk:gap-2 cpk:mt-2",
5284
5180
  children: mediaParts.map((part, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentRenderer, {
5285
5181
  type: part.type,
5286
5182
  source: part.source,
5287
5183
  filename: getFilename(part)
5288
5184
  }, index))
5289
5185
  }),
5290
- BoundMessageRenderer,
5291
5186
  BoundToolbar
5292
5187
  ]
5293
5188
  });
@@ -5991,6 +5886,73 @@ function AttachmentPreview({ attachment }) {
5991
5886
  case "document": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocumentPreview, { attachment });
5992
5887
  }
5993
5888
  }
5889
+ function Lightbox({ onClose, children }) {
5890
+ (0, react.useEffect)(() => {
5891
+ const handleKey = (e) => {
5892
+ if (e.key === "Escape") onClose();
5893
+ };
5894
+ document.addEventListener("keydown", handleKey);
5895
+ return () => document.removeEventListener("keydown", handleKey);
5896
+ }, [onClose]);
5897
+ if (typeof document === "undefined") return null;
5898
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5899
+ className: "cpk:fixed cpk:inset-0 cpk:z-[9999] cpk:flex cpk:items-center cpk:justify-center cpk:bg-black/80 cpk:animate-fade-in",
5900
+ onClick: onClose,
5901
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
5902
+ onClick: onClose,
5903
+ className: "cpk:absolute cpk:top-4 cpk:right-4 cpk:text-white cpk:bg-white/10 cpk:hover:bg-white/20 cpk:rounded-full cpk:w-10 cpk:h-10 cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer cpk:border-none cpk:z-10",
5904
+ "aria-label": "Close preview",
5905
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "cpk:w-5 cpk:h-5" })
5906
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5907
+ onClick: (e) => e.stopPropagation(),
5908
+ children
5909
+ })]
5910
+ }), document.body);
5911
+ }
5912
+ /**
5913
+ * Hook that manages lightbox open/close and uses the View Transition API to
5914
+ * morph the thumbnail into fullscreen content.
5915
+ *
5916
+ * The trick: `view-transition-name` must live on exactly ONE element at a time.
5917
+ * - Old state (thumbnail visible): name is on the thumbnail.
5918
+ * - New state (lightbox visible): name moves to the lightbox content.
5919
+ * `flushSync` ensures React commits the DOM change synchronously inside the
5920
+ * `startViewTransition` callback so the API can snapshot old → new correctly.
5921
+ */
5922
+ function useLightbox() {
5923
+ const thumbnailRef = (0, react.useRef)(null);
5924
+ const [open, setOpen] = (0, react.useState)(false);
5925
+ const vtName = (0, react.useId)();
5926
+ return {
5927
+ thumbnailRef,
5928
+ vtName,
5929
+ open,
5930
+ openLightbox: (0, react.useCallback)(() => {
5931
+ const thumb = thumbnailRef.current;
5932
+ const doc = document;
5933
+ if (doc.startViewTransition && thumb) {
5934
+ thumb.style.viewTransitionName = vtName;
5935
+ doc.startViewTransition(() => {
5936
+ thumb.style.viewTransitionName = "";
5937
+ (0, react_dom.flushSync)(() => setOpen(true));
5938
+ });
5939
+ } else setOpen(true);
5940
+ }, []),
5941
+ closeLightbox: (0, react.useCallback)(() => {
5942
+ const thumb = thumbnailRef.current;
5943
+ const doc = document;
5944
+ if (doc.startViewTransition && thumb) doc.startViewTransition(() => {
5945
+ (0, react_dom.flushSync)(() => setOpen(false));
5946
+ thumb.style.viewTransitionName = vtName;
5947
+ }).finished.then(() => {
5948
+ thumb.style.viewTransitionName = "";
5949
+ }).catch(() => {
5950
+ thumb.style.viewTransitionName = "";
5951
+ });
5952
+ else setOpen(false);
5953
+ }, [])
5954
+ };
5955
+ }
5994
5956
  function ImagePreview({ attachment }) {
5995
5957
  const src = (0, _copilotkit_shared.getSourceUrl)(attachment.source);
5996
5958
  const { thumbnailRef, vtName, open, openLightbox, closeLightbox } = useLightbox();
@@ -6330,17 +6292,14 @@ function DropOverlay() {
6330
6292
  });
6331
6293
  }
6332
6294
  function CopilotChatView({ messageView, input, scrollView, suggestionView, welcomeScreen, messages = [], autoScroll = true, isRunning = false, suggestions, suggestionLoadingIndexes, onSelectSuggestion, onSubmitMessage, onStop, inputMode, inputValue, onInputChange, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, attachments, onRemoveAttachment, onAddFile, dragOver, onDragOver, onDragLeave, onDrop, isConnecting = false, hasExplicitThreadId = false, disclaimer, children, className, ...props }) {
6333
- const [inputContainerEl, setInputContainerEl] = (0, react.useState)(null);
6295
+ const inputContainerRef = (0, react.useRef)(null);
6334
6296
  const [inputContainerHeight, setInputContainerHeight] = (0, react.useState)(0);
6335
6297
  const [isResizing, setIsResizing] = (0, react.useState)(false);
6336
6298
  const resizeTimeoutRef = (0, react.useRef)(null);
6337
6299
  const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
6338
6300
  (0, react.useEffect)(() => {
6339
- const element = inputContainerEl;
6340
- if (!element) {
6341
- setInputContainerHeight(0);
6342
- return;
6343
- }
6301
+ const element = inputContainerRef.current;
6302
+ if (!element) return;
6344
6303
  const resizeObserver = new ResizeObserver((entries) => {
6345
6304
  for (const entry of entries) {
6346
6305
  const newHeight = entry.contentRect.height;
@@ -6363,7 +6322,7 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
6363
6322
  resizeObserver.disconnect();
6364
6323
  if (resizeTimeoutRef.current) clearTimeout(resizeTimeoutRef.current);
6365
6324
  };
6366
- }, [inputContainerEl]);
6325
+ }, []);
6367
6326
  const BoundMessageView = renderSlot(messageView, CopilotChatMessageView, {
6368
6327
  messages,
6369
6328
  isRunning
@@ -6474,7 +6433,7 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
6474
6433
  dragOver && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropOverlay, {}),
6475
6434
  BoundScrollView,
6476
6435
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6477
- ref: setInputContainerEl,
6436
+ ref: inputContainerRef,
6478
6437
  "data-testid": "copilot-input-overlay",
6479
6438
  className: "cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none",
6480
6439
  children: [attachments && attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -10243,4 +10202,4 @@ Object.defineProperty(exports, 'useToast', {
10243
10202
  return useToast;
10244
10203
  }
10245
10204
  });
10246
- //# sourceMappingURL=copilotkit-DMFu29Kx.cjs.map
10205
+ //# sourceMappingURL=copilotkit-tb4zqaMK.cjs.map