@copilotkit/react-ui 1.4.8 → 1.5.0-coagents-v0-3.0

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 (65) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-CVHT5XCA.mjs → chunk-375NVWZM.mjs} +2 -2
  3. package/dist/{chunk-OMTPWC7T.mjs → chunk-3E7HY2UN.mjs} +5 -4
  4. package/dist/chunk-3E7HY2UN.mjs.map +1 -0
  5. package/dist/{chunk-RKPANT3F.mjs → chunk-7II4YL7R.mjs} +2 -6
  6. package/dist/chunk-7II4YL7R.mjs.map +1 -0
  7. package/dist/{chunk-46UJJGXP.mjs → chunk-DCNCY2PL.mjs} +113 -10
  8. package/dist/chunk-DCNCY2PL.mjs.map +1 -0
  9. package/dist/{chunk-DVMTTXGZ.mjs → chunk-F2W5FD7L.mjs} +2 -2
  10. package/dist/{chunk-4FIGRRFS.mjs → chunk-PNQVKBPN.mjs} +2 -2
  11. package/dist/{chunk-4FIGRRFS.mjs.map → chunk-PNQVKBPN.mjs.map} +1 -1
  12. package/dist/{chunk-752NGHCE.mjs → chunk-UWVGLGFQ.mjs} +7 -3
  13. package/dist/chunk-UWVGLGFQ.mjs.map +1 -0
  14. package/dist/{chunk-PNKBFDUI.mjs → chunk-WSMMTZCM.mjs} +2 -2
  15. package/dist/components/chat/Chat.d.ts +50 -5
  16. package/dist/components/chat/Chat.js +115 -12
  17. package/dist/components/chat/Chat.js.map +1 -1
  18. package/dist/components/chat/Chat.mjs +5 -5
  19. package/dist/components/chat/Messages.d.ts +3 -3
  20. package/dist/components/chat/Messages.js.map +1 -1
  21. package/dist/components/chat/Messages.mjs +1 -1
  22. package/dist/components/chat/Modal.d.ts +1 -1
  23. package/dist/components/chat/Modal.js +119 -12
  24. package/dist/components/chat/Modal.js.map +1 -1
  25. package/dist/components/chat/Modal.mjs +6 -6
  26. package/dist/components/chat/Popup.js +119 -12
  27. package/dist/components/chat/Popup.js.map +1 -1
  28. package/dist/components/chat/Popup.mjs +7 -7
  29. package/dist/components/chat/Sidebar.js +119 -12
  30. package/dist/components/chat/Sidebar.js.map +1 -1
  31. package/dist/components/chat/Sidebar.mjs +7 -7
  32. package/dist/components/chat/index.js +119 -12
  33. package/dist/components/chat/index.js.map +1 -1
  34. package/dist/components/chat/index.mjs +8 -8
  35. package/dist/components/chat/messages/RenderActionExecutionMessage.js +4 -3
  36. package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
  37. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +1 -1
  38. package/dist/components/dev-console/console.js +1 -1
  39. package/dist/components/dev-console/console.js.map +1 -1
  40. package/dist/components/dev-console/console.mjs +2 -2
  41. package/dist/components/dev-console/index.js +1 -1
  42. package/dist/components/dev-console/index.js.map +1 -1
  43. package/dist/components/dev-console/index.mjs +2 -2
  44. package/dist/components/dev-console/utils.js +1 -1
  45. package/dist/components/dev-console/utils.js.map +1 -1
  46. package/dist/components/dev-console/utils.mjs +1 -1
  47. package/dist/components/index.js +119 -12
  48. package/dist/components/index.js.map +1 -1
  49. package/dist/components/index.mjs +8 -8
  50. package/dist/index.js +121 -14
  51. package/dist/index.js.map +1 -1
  52. package/dist/index.mjs +8 -8
  53. package/package.json +4 -4
  54. package/src/components/chat/Chat.tsx +173 -7
  55. package/src/components/chat/Messages.tsx +2 -9
  56. package/src/components/chat/Modal.tsx +4 -0
  57. package/src/components/chat/messages/RenderActionExecutionMessage.tsx +10 -3
  58. package/src/components/dev-console/utils.ts +1 -1
  59. package/dist/chunk-46UJJGXP.mjs.map +0 -1
  60. package/dist/chunk-752NGHCE.mjs.map +0 -1
  61. package/dist/chunk-OMTPWC7T.mjs.map +0 -1
  62. package/dist/chunk-RKPANT3F.mjs.map +0 -1
  63. /package/dist/{chunk-CVHT5XCA.mjs.map → chunk-375NVWZM.mjs.map} +0 -0
  64. /package/dist/{chunk-DVMTTXGZ.mjs.map → chunk-F2W5FD7L.mjs.map} +0 -0
  65. /package/dist/{chunk-PNKBFDUI.mjs.map → chunk-WSMMTZCM.mjs.map} +0 -0
@@ -948,9 +948,9 @@ var import_react7 = require("react");
948
948
  var import_react_syntax_highlighter = require("react-syntax-highlighter");
949
949
 
950
950
  // src/hooks/use-copy-to-clipboard.tsx
951
- var React6 = __toESM(require("react"));
951
+ var React5 = __toESM(require("react"));
952
952
  function useCopyToClipboard({ timeout = 2e3 }) {
953
- const [isCopied, setIsCopied] = React6.useState(false);
953
+ const [isCopied, setIsCopied] = React5.useState(false);
954
954
  const copyToClipboard = (value) => {
955
955
  var _a;
956
956
  if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
@@ -1446,8 +1446,8 @@ function RenderActionExecutionMessage(props) {
1446
1446
  const { chatComponentsCache } = (0, import_react_core3.useCopilotContext)();
1447
1447
  const { icons } = useChatContext();
1448
1448
  if (message.isActionExecutionMessage()) {
1449
- if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
1450
- const render = chatComponentsCache.current.actions[message.name];
1449
+ if (chatComponentsCache.current !== null && (chatComponentsCache.current.actions[message.name] || chatComponentsCache.current.actions["*"])) {
1450
+ const render = chatComponentsCache.current.actions[message.name] || chatComponentsCache.current.actions["*"];
1451
1451
  if (typeof render === "string") {
1452
1452
  if (isCurrentMessage && inProgress) {
1453
1453
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
@@ -1470,7 +1470,8 @@ function RenderActionExecutionMessage(props) {
1470
1470
  const toRender = render({
1471
1471
  status,
1472
1472
  args,
1473
- result: actionResult
1473
+ result: actionResult,
1474
+ name: message.name
1474
1475
  });
1475
1476
  if (!toRender && status === "complete") {
1476
1477
  return null;
@@ -1784,7 +1785,7 @@ function logMessages(context) {
1784
1785
  type: "ActionExecutionMessage",
1785
1786
  role: void 0,
1786
1787
  name: message.name,
1787
- scope: message.scope,
1788
+ scope: message.parentMessageId,
1788
1789
  content: message.arguments
1789
1790
  };
1790
1791
  } else if (message.isResultMessage()) {
@@ -2310,6 +2311,7 @@ function DebugMenuButton({
2310
2311
  }
2311
2312
 
2312
2313
  // src/components/chat/Chat.tsx
2314
+ var import_react_core9 = require("@copilotkit/react-core");
2313
2315
  var import_jsx_runtime21 = require("react/jsx-runtime");
2314
2316
  function CopilotChat({
2315
2317
  instructions,
@@ -2317,6 +2319,8 @@ function CopilotChat({
2317
2319
  makeSystemMessage,
2318
2320
  showResponseButton = true,
2319
2321
  onInProgress,
2322
+ onStopGeneration,
2323
+ onReloadMessages,
2320
2324
  Messages: Messages2 = Messages,
2321
2325
  RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
2322
2326
  RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
@@ -2339,7 +2343,13 @@ function CopilotChat({
2339
2343
  sendMessage,
2340
2344
  stopGeneration,
2341
2345
  reloadMessages
2342
- } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
2346
+ } = useCopilotChatLogic(
2347
+ makeSystemMessage,
2348
+ onInProgress,
2349
+ onSubmitMessage,
2350
+ onStopGeneration,
2351
+ onReloadMessages
2352
+ );
2343
2353
  const chatContext = import_react12.default.useContext(ChatContext);
2344
2354
  const isVisible = chatContext ? chatContext.open : true;
2345
2355
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
@@ -2395,8 +2405,16 @@ function WrappedCopilotChat({
2395
2405
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_jsx_runtime21.Fragment, { children });
2396
2406
  }
2397
2407
  var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
2398
- var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
2399
- const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core8.useCopilotChat)({
2408
+ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
2409
+ var _a;
2410
+ const {
2411
+ visibleMessages,
2412
+ appendMessage,
2413
+ reloadMessages: defaultReloadMessages,
2414
+ stopGeneration: defaultStopGeneration,
2415
+ runChatCompletion,
2416
+ isLoading
2417
+ } = (0, import_react_core8.useCopilotChat)({
2400
2418
  id: (0, import_shared3.randomId)(),
2401
2419
  makeSystemMessage
2402
2420
  });
@@ -2404,8 +2422,8 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
2404
2422
  const suggestionsAbortControllerRef = (0, import_react12.useRef)(null);
2405
2423
  const debounceTimerRef = (0, import_react12.useRef)();
2406
2424
  const abortSuggestions = () => {
2407
- var _a;
2408
- (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
2425
+ var _a2;
2426
+ (_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort();
2409
2427
  suggestionsAbortControllerRef.current = null;
2410
2428
  };
2411
2429
  const generalContext = (0, import_react_core8.useCopilotContext)();
@@ -2431,7 +2449,13 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
2431
2449
  return () => {
2432
2450
  clearTimeout(debounceTimerRef.current);
2433
2451
  };
2434
- }, [isLoading, context.chatSuggestionConfiguration]);
2452
+ }, [
2453
+ isLoading,
2454
+ context.chatSuggestionConfiguration,
2455
+ // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
2456
+ // global context
2457
+ visibleMessages.length == 0
2458
+ ]);
2435
2459
  const sendMessage = (messageContent) => __async(void 0, null, function* () {
2436
2460
  abortSuggestions();
2437
2461
  setCurrentSuggestions([]);
@@ -2449,6 +2473,85 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
2449
2473
  appendMessage(message);
2450
2474
  return message;
2451
2475
  });
2476
+ const messages = visibleMessages;
2477
+ const { setMessages } = messagesContext;
2478
+ const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
2479
+ const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
2480
+ if (generalContext.agentSession) {
2481
+ generalContext.setAgentSession(__spreadProps(__spreadValues({}, generalContext.agentSession), {
2482
+ nodeName: void 0,
2483
+ threadId: void 0
2484
+ }));
2485
+ generalContext.setCoagentStates((prevAgentStates) => {
2486
+ return __spreadProps(__spreadValues({}, prevAgentStates), {
2487
+ [generalContext.agentSession.agentName]: __spreadProps(__spreadValues({}, prevAgentStates[generalContext.agentSession.agentName]), {
2488
+ threadId: void 0,
2489
+ nodeName: void 0,
2490
+ runId: void 0
2491
+ })
2492
+ });
2493
+ });
2494
+ }
2495
+ });
2496
+ const runCurrentAgent = (hint) => __async(void 0, null, function* () {
2497
+ if (generalContext.agentSession) {
2498
+ yield (0, import_react_core9.runAgent)(
2499
+ generalContext.agentSession.agentName,
2500
+ context,
2501
+ appendMessage,
2502
+ runChatCompletion,
2503
+ hint
2504
+ );
2505
+ }
2506
+ });
2507
+ const stopCurrentAgent = () => {
2508
+ if (generalContext.agentSession) {
2509
+ (0, import_react_core9.stopAgent)(generalContext.agentSession.agentName, context);
2510
+ }
2511
+ };
2512
+ const setCurrentAgentState = (state) => {
2513
+ if (generalContext.agentSession) {
2514
+ generalContext.setCoagentStates((prevAgentStates) => {
2515
+ return __spreadProps(__spreadValues({}, prevAgentStates), {
2516
+ [generalContext.agentSession.agentName]: {
2517
+ state
2518
+ }
2519
+ });
2520
+ });
2521
+ }
2522
+ };
2523
+ function stopGeneration() {
2524
+ if (onStopGeneration) {
2525
+ onStopGeneration({
2526
+ messages,
2527
+ setMessages,
2528
+ stopGeneration: defaultStopGeneration,
2529
+ currentAgentName,
2530
+ restartCurrentAgent,
2531
+ stopCurrentAgent,
2532
+ runCurrentAgent,
2533
+ setCurrentAgentState
2534
+ });
2535
+ } else {
2536
+ defaultStopGeneration();
2537
+ }
2538
+ }
2539
+ function reloadMessages() {
2540
+ if (onReloadMessages) {
2541
+ onReloadMessages({
2542
+ messages,
2543
+ setMessages,
2544
+ stopGeneration: defaultStopGeneration,
2545
+ currentAgentName,
2546
+ restartCurrentAgent,
2547
+ stopCurrentAgent,
2548
+ runCurrentAgent,
2549
+ setCurrentAgentState
2550
+ });
2551
+ } else {
2552
+ defaultReloadMessages();
2553
+ }
2554
+ }
2452
2555
  return {
2453
2556
  visibleMessages,
2454
2557
  isLoading,
@@ -2468,6 +2571,8 @@ var CopilotModal = ({
2468
2571
  hitEscapeToClose = true,
2469
2572
  onSetOpen,
2470
2573
  onSubmitMessage,
2574
+ onStopGeneration,
2575
+ onReloadMessages,
2471
2576
  shortcut = "/",
2472
2577
  icons,
2473
2578
  labels,
@@ -2505,6 +2610,8 @@ var CopilotModal = ({
2505
2610
  {
2506
2611
  instructions,
2507
2612
  onSubmitMessage,
2613
+ onStopGeneration,
2614
+ onReloadMessages,
2508
2615
  makeSystemMessage,
2509
2616
  showResponseButton,
2510
2617
  onInProgress,