@copilotkit/react-core 1.56.1 → 1.56.2-canary.pin-to-send

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.
Files changed (48) hide show
  1. package/dist/{copilotkit-Cj2ZIxVr.mjs → copilotkit-BBYbekCa.mjs} +234 -60
  2. package/dist/copilotkit-BBYbekCa.mjs.map +1 -0
  3. package/dist/{copilotkit-CSJw5BG8.cjs → copilotkit-D5JT2Pu3.cjs} +233 -59
  4. package/dist/copilotkit-D5JT2Pu3.cjs.map +1 -0
  5. package/dist/{copilotkit-CCbxm6JM.d.mts → copilotkit-DArT2Iuw.d.mts} +62 -18
  6. package/dist/copilotkit-DArT2Iuw.d.mts.map +1 -0
  7. package/dist/{copilotkit-BtP7w7cT.d.cts → copilotkit-KEc28l8G.d.cts} +62 -18
  8. package/dist/copilotkit-KEc28l8G.d.cts.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.mts +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.umd.js +16 -40
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/index.cjs +1 -1
  16. package/dist/v2/index.css +1 -1
  17. package/dist/v2/index.d.cts +2 -2
  18. package/dist/v2/index.d.mts +2 -2
  19. package/dist/v2/index.mjs +1 -1
  20. package/dist/v2/index.umd.js +232 -62
  21. package/dist/v2/index.umd.js.map +1 -1
  22. package/package.json +6 -6
  23. package/src/v2/components/chat/CopilotChat.tsx +80 -4
  24. package/src/v2/components/chat/CopilotChatInput.tsx +22 -0
  25. package/src/v2/components/chat/CopilotChatView.tsx +206 -11
  26. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +66 -0
  27. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +300 -2
  28. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +56 -0
  29. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +94 -0
  30. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -1
  31. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +37 -0
  32. package/src/v2/components/chat/index.ts +2 -0
  33. package/src/v2/components/chat/last-user-message-context.ts +21 -0
  34. package/src/v2/components/chat/normalize-auto-scroll.ts +17 -0
  35. package/src/v2/components/license-warning-banner.tsx +20 -1
  36. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +6 -0
  37. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +6 -0
  38. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +76 -50
  39. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +219 -0
  40. package/src/v2/hooks/__tests__/use-threads.test.tsx +68 -0
  41. package/src/v2/hooks/use-agent.tsx +34 -77
  42. package/src/v2/hooks/use-pin-to-send.ts +94 -0
  43. package/src/v2/hooks/use-threads.tsx +55 -12
  44. package/src/v2/providers/CopilotKitProvider.tsx +2 -11
  45. package/dist/copilotkit-BtP7w7cT.d.cts.map +0 -1
  46. package/dist/copilotkit-CCbxm6JM.d.mts.map +0 -1
  47. package/dist/copilotkit-CSJw5BG8.cjs.map +0 -1
  48. package/dist/copilotkit-Cj2ZIxVr.mjs.map +0 -1
package/dist/index.umd.js CHANGED
@@ -230,6 +230,8 @@ react_markdown = __toESM(react_markdown);
230
230
 
231
231
  //#endregion
232
232
  //#region src/v2/components/license-warning-banner.tsx
233
+ const LICENSE_BANNER_OFFSET_PX = 52;
234
+ const LICENSE_BANNER_OFFSET_VAR = "--copilotkit-license-banner-offset";
233
235
  const BANNER_STYLES = {
234
236
  base: {
235
237
  position: "fixed",
@@ -271,6 +273,14 @@ react_markdown = __toESM(react_markdown);
271
273
  }
272
274
  }
273
275
  function BannerShell({ severity, message, actionLabel, actionUrl, onDismiss }) {
276
+ (0, react.useEffect)(() => {
277
+ if (typeof document === "undefined") return;
278
+ const root = document.documentElement;
279
+ root.style.setProperty(LICENSE_BANNER_OFFSET_VAR, `${LICENSE_BANNER_OFFSET_PX}px`);
280
+ return () => {
281
+ root.style.removeProperty(LICENSE_BANNER_OFFSET_VAR);
282
+ };
283
+ }, []);
274
284
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
275
285
  style: {
276
286
  ...BANNER_STYLES.base,
@@ -2225,7 +2235,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2225
2235
  didMountRef.current = true;
2226
2236
  }, []);
2227
2237
  (0, react.useEffect)(() => {
2228
- if (defaultThrottleMs !== void 0 && (!Number.isFinite(defaultThrottleMs) || defaultThrottleMs < 0)) console.error(`CopilotKitProvider: defaultThrottleMs must be a non-negative finite number, got ${defaultThrottleMs}. useAgent hooks without an explicit throttleMs will fall back to unthrottled.`);
2229
2238
  copilotkit.setDefaultThrottleMs(defaultThrottleMs);
2230
2239
  }, [copilotkit, defaultThrottleMs]);
2231
2240
  const designSkill = (_openGenerativeUI$des = openGenerativeUI === null || openGenerativeUI === void 0 ? void 0 : openGenerativeUI.designSkill) !== null && _openGenerativeUI$des !== void 0 ? _openGenerativeUI$des : DEFAULT_DESIGN_SKILL;
@@ -2447,16 +2456,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2447
2456
  const providerThrottleMs = copilotkit.defaultThrottleMs;
2448
2457
  const chatConfig = useCopilotChatConfiguration();
2449
2458
  (_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
2450
- const effectiveThrottleMs = (0, react.useMemo)(() => {
2451
- var _ref;
2452
- const resolved = (_ref = throttleMs !== null && throttleMs !== void 0 ? throttleMs : providerThrottleMs) !== null && _ref !== void 0 ? _ref : 0;
2453
- if (!Number.isFinite(resolved) || resolved < 0) {
2454
- const source = throttleMs !== void 0 ? "hook-level throttleMs" : "provider-level defaultThrottleMs";
2455
- console.error(`useAgent: ${source} must be a non-negative finite number, got ${resolved}. Falling back to unthrottled.`);
2456
- return 0;
2457
- }
2458
- return resolved;
2459
- }, [throttleMs, providerThrottleMs]);
2460
2459
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
2461
2460
  const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
2462
2461
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
@@ -2520,9 +2519,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2520
2519
  ]);
2521
2520
  (0, react.useEffect)(() => {
2522
2521
  if (updateFlags.length === 0) return;
2523
- const handlers = {};
2524
- let timerId = null;
2525
2522
  let active = true;
2523
+ const handlers = {};
2526
2524
  let batchScheduled = false;
2527
2525
  const batchedForceUpdate = () => {
2528
2526
  if (!active) return;
@@ -2534,46 +2532,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2534
2532
  });
2535
2533
  }
2536
2534
  };
2537
- if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) {
2538
- const ms = effectiveThrottleMs;
2539
- if (ms > 0) {
2540
- let throttleActive = false;
2541
- let pending = false;
2542
- const throttledNotify = () => {
2543
- if (!active) return;
2544
- if (!throttleActive) {
2545
- throttleActive = true;
2546
- pending = false;
2547
- forceUpdate();
2548
- timerId = setTimeout(function trailingEdge() {
2549
- timerId = null;
2550
- if (active && pending) {
2551
- pending = false;
2552
- forceUpdate();
2553
- timerId = setTimeout(trailingEdge, ms);
2554
- } else throttleActive = false;
2555
- }, ms);
2556
- } else pending = true;
2557
- };
2558
- handlers.onMessagesChanged = throttledNotify;
2559
- } else handlers.onMessagesChanged = forceUpdate;
2560
- }
2535
+ if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = forceUpdate;
2561
2536
  if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
2562
2537
  if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
2563
2538
  handlers.onRunInitialized = batchedForceUpdate;
2564
2539
  handlers.onRunFinalized = batchedForceUpdate;
2565
2540
  handlers.onRunFailed = batchedForceUpdate;
2541
+ handlers.onRunErrorEvent = batchedForceUpdate;
2566
2542
  }
2567
- const subscription = agent.subscribe(handlers);
2543
+ const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
2568
2544
  return () => {
2569
2545
  active = false;
2570
- if (timerId !== null) clearTimeout(timerId);
2571
2546
  subscription.unsubscribe();
2572
2547
  };
2573
2548
  }, [
2574
2549
  agent,
2575
2550
  forceUpdate,
2576
- effectiveThrottleMs,
2551
+ throttleMs,
2552
+ providerThrottleMs,
2577
2553
  updateFlags
2578
2554
  ]);
2579
2555
  (0, react.useEffect)(() => {