@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.
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  (function(global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./index.css'), require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('tailwind-merge'), require('lucide-react'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('@radix-ui/react-slot'), require('class-variance-authority'), require('clsx'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('streamdown'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('@tanstack/react-virtual'), require('use-stick-to-bottom')) :
5
- typeof define === 'function' && define.amd ? define(['exports', './index.css', '@copilotkit/core', '@ag-ui/client', 'react', 'tailwind-merge', 'lucide-react', '@copilotkit/shared', 'react/jsx-runtime', '@radix-ui/react-slot', 'class-variance-authority', 'clsx', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', 'streamdown', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', '@tanstack/react-virtual', 'use-stick-to-bottom'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCoreV2 = {}), global.src_v2_index_css,global.CopilotKitCore,global.AgUIClient,global.React,global.tailwindMerge,global.lucideReact,global.CopilotKitShared,global.ReactJsxRuntime,global.RadixReactSlot,global.classVarianceAuthority,global.clsx,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.streamdown,global.Zod,global.LitLabsReact,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global._tanstack_react_virtual,global.useStickToBottom));
7
- })(this, function(exports, src_v2_index_css, _copilotkit_core, _ag_ui_client, react, tailwind_merge, lucide_react, _copilotkit_shared, react_jsx_runtime, _radix_ui_react_slot, class_variance_authority, clsx, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, streamdown, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, _tanstack_react_virtual, use_stick_to_bottom) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./index.css'), require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('tailwind-merge'), require('lucide-react'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('@radix-ui/react-slot'), require('class-variance-authority'), require('clsx'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('streamdown'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('@tanstack/react-virtual'), require('react-dom'), require('use-stick-to-bottom')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', './index.css', '@copilotkit/core', '@ag-ui/client', 'react', 'tailwind-merge', 'lucide-react', '@copilotkit/shared', 'react/jsx-runtime', '@radix-ui/react-slot', 'class-variance-authority', 'clsx', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', 'streamdown', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', '@tanstack/react-virtual', 'react-dom', 'use-stick-to-bottom'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCoreV2 = {}), global.src_v2_index_css,global.CopilotKitCore,global.AgUIClient,global.React,global.tailwindMerge,global.lucideReact,global.CopilotKitShared,global.ReactJsxRuntime,global.RadixReactSlot,global.classVarianceAuthority,global.clsx,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.streamdown,global.Zod,global.LitLabsReact,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global._tanstack_react_virtual,global.ReactDOM,global.useStickToBottom));
7
+ })(this, function(exports, src_v2_index_css, _copilotkit_core, _ag_ui_client, react, tailwind_merge, lucide_react, _copilotkit_shared, react_jsx_runtime, _radix_ui_react_slot, class_variance_authority, clsx, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, streamdown, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, _tanstack_react_virtual, react_dom, use_stick_to_bottom) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -4393,20 +4393,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4393
4393
  return consumer;
4394
4394
  }, [normalizedConfig, resolvedConsumerAgentId]);
4395
4395
  const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
4396
- const isDynamicConfigType = (0, react.useMemo)(() => !!normalizedConfig && "instructions" in normalizedConfig, [normalizedConfig]);
4397
4396
  const requestReload = (0, react.useCallback)(() => {
4398
4397
  if (!normalizedConfig) return;
4399
4398
  if (isGlobalConfig) {
4400
4399
  var _copilotkit$agents;
4401
- const seen = /* @__PURE__ */ new Set();
4402
4400
  const agents = Object.values((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
4403
4401
  for (const entry of agents) {
4404
4402
  const agentId = entry.agentId;
4405
4403
  if (!agentId) continue;
4406
- seen.add(agentId);
4407
4404
  if (!entry.isRunning) copilotkit.reloadSuggestions(agentId);
4408
4405
  }
4409
- if (targetAgentId && !seen.has(targetAgentId)) copilotkit.reloadSuggestions(targetAgentId);
4410
4406
  return;
4411
4407
  }
4412
4408
  if (!targetAgentId) return;
@@ -4451,26 +4447,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4451
4447
  requestReload,
4452
4448
  ...extraDeps
4453
4449
  ]);
4454
- (0, react.useEffect)(() => {
4455
- if (!normalizedConfig || !isDynamicConfigType) return;
4456
- if (!targetAgentId) return;
4457
- if (!!copilotkit.getAgent(targetAgentId)) return;
4458
- const subscription = copilotkit.subscribe({ onAgentsChanged: () => {
4459
- if (copilotkit.getAgent(targetAgentId)) {
4460
- requestReload();
4461
- subscription.unsubscribe();
4462
- }
4463
- } });
4464
- return () => {
4465
- subscription.unsubscribe();
4466
- };
4467
- }, [
4468
- copilotkit,
4469
- normalizedConfig,
4470
- isDynamicConfigType,
4471
- targetAgentId,
4472
- requestReload
4473
- ]);
4474
4450
  }
4475
4451
  function isDynamicConfig(config) {
4476
4452
  return "instructions" in config;
@@ -5151,101 +5127,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5151
5127
  CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
5152
5128
  var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
5153
5129
 
5154
- //#endregion
5155
- //#region src/v2/components/chat/Lightbox.tsx
5156
- function Lightbox({ onClose, children }) {
5157
- (0, react.useEffect)(() => {
5158
- const handleKey = (e) => {
5159
- if (e.key === "Escape") onClose();
5160
- };
5161
- document.addEventListener("keydown", handleKey);
5162
- return () => document.removeEventListener("keydown", handleKey);
5163
- }, [onClose]);
5164
- if (typeof document === "undefined") return null;
5165
- return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5166
- 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",
5167
- onClick: onClose,
5168
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
5169
- onClick: onClose,
5170
- 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",
5171
- "aria-label": "Close preview",
5172
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "cpk:w-5 cpk:h-5" })
5173
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5174
- onClick: (e) => e.stopPropagation(),
5175
- children
5176
- })]
5177
- }), document.body);
5178
- }
5179
- /**
5180
- * Hook that manages lightbox open/close and uses the View Transition API to
5181
- * morph the thumbnail into fullscreen content.
5182
- *
5183
- * The trick: `view-transition-name` must live on exactly ONE element at a time.
5184
- * - Old state (thumbnail visible): name is on the thumbnail.
5185
- * - New state (lightbox visible): name moves to the lightbox content.
5186
- * `flushSync` ensures React commits the DOM change synchronously inside the
5187
- * `startViewTransition` callback so the API can snapshot old → new correctly.
5188
- */
5189
- function useLightbox() {
5190
- const thumbnailRef = (0, react.useRef)(null);
5191
- const [open, setOpen] = (0, react.useState)(false);
5192
- const vtName = (0, react.useId)();
5193
- return {
5194
- thumbnailRef,
5195
- vtName,
5196
- open,
5197
- openLightbox: (0, react.useCallback)(() => {
5198
- const thumb = thumbnailRef.current;
5199
- const doc = document;
5200
- if (doc.startViewTransition && thumb) {
5201
- thumb.style.viewTransitionName = vtName;
5202
- doc.startViewTransition(() => {
5203
- thumb.style.viewTransitionName = "";
5204
- (0, react_dom.flushSync)(() => setOpen(true));
5205
- });
5206
- } else setOpen(true);
5207
- }, [vtName]),
5208
- closeLightbox: (0, react.useCallback)(() => {
5209
- const thumb = thumbnailRef.current;
5210
- const doc = document;
5211
- if (doc.startViewTransition && thumb) doc.startViewTransition(() => {
5212
- (0, react_dom.flushSync)(() => setOpen(false));
5213
- thumb.style.viewTransitionName = vtName;
5214
- }).finished.then(() => {
5215
- thumb.style.viewTransitionName = "";
5216
- }).catch(() => {
5217
- thumb.style.viewTransitionName = "";
5218
- });
5219
- else setOpen(false);
5220
- }, [vtName])
5221
- };
5222
- }
5223
-
5224
5130
  //#endregion
5225
5131
  //#region src/v2/components/chat/CopilotChatAttachmentRenderer.tsx
5226
5132
  const ImageAttachment = (0, react.memo)(function ImageAttachment({ src, className }) {
5227
5133
  const [error, setError] = (0, react.useState)(false);
5228
- const { thumbnailRef, vtName, open, openLightbox, closeLightbox } = useLightbox();
5229
5134
  if (error) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5230
5135
  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),
5231
5136
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Failed to load image" })
5232
5137
  });
5233
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5234
- ref: thumbnailRef,
5138
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5235
5139
  src,
5236
5140
  alt: "Image attachment",
5237
- 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),
5238
- onClick: openLightbox,
5141
+ className: cn("cpk:max-w-full cpk:h-auto cpk:rounded-lg", className),
5239
5142
  onError: () => setError(true)
5240
- }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Lightbox, {
5241
- onClose: closeLightbox,
5242
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
5243
- style: { viewTransitionName: vtName },
5244
- src,
5245
- alt: "Image attachment",
5246
- className: "cpk:max-w-[90vw] cpk:max-h-[90vh] cpk:object-contain cpk:rounded-lg"
5247
- })
5248
- })] });
5143
+ });
5249
5144
  });
5250
5145
  const AudioAttachment = (0, react.memo)(function AudioAttachment({ src, filename, className }) {
5251
5146
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -5371,15 +5266,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5371
5266
  "data-message-id": message.id,
5372
5267
  ...props,
5373
5268
  children: [
5269
+ BoundMessageRenderer,
5374
5270
  mediaParts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5375
- className: "cpk:flex cpk:flex-row cpk:flex-wrap cpk:justify-end cpk:gap-2 cpk:mb-2",
5271
+ className: "cpk:flex cpk:flex-col cpk:items-end cpk:gap-2 cpk:mt-2",
5376
5272
  children: mediaParts.map((part, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentRenderer, {
5377
5273
  type: part.type,
5378
5274
  source: part.source,
5379
5275
  filename: getFilename(part)
5380
5276
  }, index))
5381
5277
  }),
5382
- BoundMessageRenderer,
5383
5278
  BoundToolbar
5384
5279
  ]
5385
5280
  });
@@ -6097,6 +5992,73 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6097
5992
  case "document": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocumentPreview, { attachment });
6098
5993
  }
6099
5994
  }
5995
+ function Lightbox({ onClose, children }) {
5996
+ (0, react.useEffect)(() => {
5997
+ const handleKey = (e) => {
5998
+ if (e.key === "Escape") onClose();
5999
+ };
6000
+ document.addEventListener("keydown", handleKey);
6001
+ return () => document.removeEventListener("keydown", handleKey);
6002
+ }, [onClose]);
6003
+ if (typeof document === "undefined") return null;
6004
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6005
+ 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",
6006
+ onClick: onClose,
6007
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
6008
+ onClick: onClose,
6009
+ 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",
6010
+ "aria-label": "Close preview",
6011
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "cpk:w-5 cpk:h-5" })
6012
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6013
+ onClick: (e) => e.stopPropagation(),
6014
+ children
6015
+ })]
6016
+ }), document.body);
6017
+ }
6018
+ /**
6019
+ * Hook that manages lightbox open/close and uses the View Transition API to
6020
+ * morph the thumbnail into fullscreen content.
6021
+ *
6022
+ * The trick: `view-transition-name` must live on exactly ONE element at a time.
6023
+ * - Old state (thumbnail visible): name is on the thumbnail.
6024
+ * - New state (lightbox visible): name moves to the lightbox content.
6025
+ * `flushSync` ensures React commits the DOM change synchronously inside the
6026
+ * `startViewTransition` callback so the API can snapshot old → new correctly.
6027
+ */
6028
+ function useLightbox() {
6029
+ const thumbnailRef = (0, react.useRef)(null);
6030
+ const [open, setOpen] = (0, react.useState)(false);
6031
+ const vtName = (0, react.useId)();
6032
+ return {
6033
+ thumbnailRef,
6034
+ vtName,
6035
+ open,
6036
+ openLightbox: (0, react.useCallback)(() => {
6037
+ const thumb = thumbnailRef.current;
6038
+ const doc = document;
6039
+ if (doc.startViewTransition && thumb) {
6040
+ thumb.style.viewTransitionName = vtName;
6041
+ doc.startViewTransition(() => {
6042
+ thumb.style.viewTransitionName = "";
6043
+ (0, react_dom.flushSync)(() => setOpen(true));
6044
+ });
6045
+ } else setOpen(true);
6046
+ }, []),
6047
+ closeLightbox: (0, react.useCallback)(() => {
6048
+ const thumb = thumbnailRef.current;
6049
+ const doc = document;
6050
+ if (doc.startViewTransition && thumb) doc.startViewTransition(() => {
6051
+ (0, react_dom.flushSync)(() => setOpen(false));
6052
+ thumb.style.viewTransitionName = vtName;
6053
+ }).finished.then(() => {
6054
+ thumb.style.viewTransitionName = "";
6055
+ }).catch(() => {
6056
+ thumb.style.viewTransitionName = "";
6057
+ });
6058
+ else setOpen(false);
6059
+ }, [])
6060
+ };
6061
+ }
6100
6062
  function ImagePreview({ attachment }) {
6101
6063
  const src = (0, _copilotkit_shared.getSourceUrl)(attachment.source);
6102
6064
  const { thumbnailRef, vtName, open, openLightbox, closeLightbox } = useLightbox();
@@ -6436,17 +6398,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6436
6398
  });
6437
6399
  }
6438
6400
  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 }) {
6439
- const [inputContainerEl, setInputContainerEl] = (0, react.useState)(null);
6401
+ const inputContainerRef = (0, react.useRef)(null);
6440
6402
  const [inputContainerHeight, setInputContainerHeight] = (0, react.useState)(0);
6441
6403
  const [isResizing, setIsResizing] = (0, react.useState)(false);
6442
6404
  const resizeTimeoutRef = (0, react.useRef)(null);
6443
6405
  const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
6444
6406
  (0, react.useEffect)(() => {
6445
- const element = inputContainerEl;
6446
- if (!element) {
6447
- setInputContainerHeight(0);
6448
- return;
6449
- }
6407
+ const element = inputContainerRef.current;
6408
+ if (!element) return;
6450
6409
  const resizeObserver = new ResizeObserver((entries) => {
6451
6410
  for (const entry of entries) {
6452
6411
  const newHeight = entry.contentRect.height;
@@ -6469,7 +6428,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6469
6428
  resizeObserver.disconnect();
6470
6429
  if (resizeTimeoutRef.current) clearTimeout(resizeTimeoutRef.current);
6471
6430
  };
6472
- }, [inputContainerEl]);
6431
+ }, []);
6473
6432
  const BoundMessageView = renderSlot(messageView, CopilotChatMessageView, {
6474
6433
  messages,
6475
6434
  isRunning
@@ -6580,7 +6539,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6580
6539
  dragOver && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropOverlay, {}),
6581
6540
  BoundScrollView,
6582
6541
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6583
- ref: setInputContainerEl,
6542
+ ref: inputContainerRef,
6584
6543
  "data-testid": "copilot-input-overlay",
6585
6544
  className: "cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none",
6586
6545
  children: [attachments && attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {