@copilotkit/react-core 1.50.0-beta.1 → 1.50.0-beta.3

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 (194) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{chunk-IUSKVYUI.mjs → chunk-2CYJN455.mjs} +2 -1
  3. package/dist/{chunk-IUSKVYUI.mjs.map → chunk-2CYJN455.mjs.map} +1 -1
  4. package/dist/{chunk-3GURHDG7.mjs → chunk-4HRUQH6U.mjs} +3 -3
  5. package/dist/{chunk-FBD24VEH.mjs → chunk-7HI6VLJJ.mjs} +5 -5
  6. package/dist/{chunk-FBD24VEH.mjs.map → chunk-7HI6VLJJ.mjs.map} +1 -1
  7. package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
  8. package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
  9. package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
  10. package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
  11. package/dist/{chunk-GMI4KO4X.mjs → chunk-AMUONDZ2.mjs} +2 -2
  12. package/dist/{chunk-DCHSCK62.mjs → chunk-B66SA6EH.mjs} +45 -51
  13. package/dist/chunk-B66SA6EH.mjs.map +1 -0
  14. package/dist/{chunk-7BYHZLPL.mjs → chunk-BTZ3TJVX.mjs} +6 -6
  15. package/dist/chunk-BTZ3TJVX.mjs.map +1 -0
  16. package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
  17. package/dist/{chunk-CB7CRBDG.mjs → chunk-FBVI3LQ6.mjs} +11 -11
  18. package/dist/chunk-FBVI3LQ6.mjs.map +1 -0
  19. package/dist/chunk-I76HKHPJ.mjs +32 -0
  20. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  21. package/dist/{chunk-BR5YEYZJ.mjs → chunk-IUNU4CUG.mjs} +5 -5
  22. package/dist/{chunk-UJBV5GAG.mjs → chunk-M7EVKKUZ.mjs} +20 -39
  23. package/dist/chunk-M7EVKKUZ.mjs.map +1 -0
  24. package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
  25. package/dist/{chunk-NROJOTQP.mjs → chunk-QNUAXSDP.mjs} +9 -6
  26. package/dist/chunk-QNUAXSDP.mjs.map +1 -0
  27. package/dist/{chunk-JRT5BJF3.mjs → chunk-SHHPDZUK.mjs} +2 -2
  28. package/dist/{chunk-LHERIF3L.mjs → chunk-SNON4QA6.mjs} +4 -4
  29. package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
  30. package/dist/chunk-T2VBHAAP.mjs.map +1 -0
  31. package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
  32. package/dist/{chunk-R4MR43UQ.mjs → chunk-VV56AVPB.mjs} +33 -9
  33. package/dist/chunk-VV56AVPB.mjs.map +1 -0
  34. package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
  35. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  36. package/dist/{chunk-3R423LZT.mjs → chunk-XFXT2VNX.mjs} +3 -3
  37. package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
  38. package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
  39. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  40. package/dist/components/CopilotListeners.js +13 -146
  41. package/dist/components/CopilotListeners.js.map +1 -1
  42. package/dist/components/CopilotListeners.mjs +1 -6
  43. package/dist/components/copilot-provider/copilot-messages.js +1 -1
  44. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  45. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  46. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  47. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  48. package/dist/components/copilot-provider/copilotkit.js +35 -40
  49. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  50. package/dist/components/copilot-provider/copilotkit.mjs +14 -14
  51. package/dist/components/copilot-provider/index.d.ts +1 -1
  52. package/dist/components/copilot-provider/index.js +35 -40
  53. package/dist/components/copilot-provider/index.js.map +1 -1
  54. package/dist/components/copilot-provider/index.mjs +14 -14
  55. package/dist/components/dev-console/console-trigger.js +1 -1
  56. package/dist/components/dev-console/console-trigger.js.map +1 -1
  57. package/dist/components/dev-console/console-trigger.mjs +3 -3
  58. package/dist/components/dev-console/developer-console-modal.js +1 -1
  59. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  60. package/dist/components/dev-console/developer-console-modal.mjs +2 -2
  61. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  62. package/dist/components/index.d.ts +1 -1
  63. package/dist/components/index.js +35 -40
  64. package/dist/components/index.js.map +1 -1
  65. package/dist/components/index.mjs +14 -14
  66. package/dist/context/copilot-context.d.ts +1 -1
  67. package/dist/context/copilot-context.js +1 -1
  68. package/dist/context/copilot-context.js.map +1 -1
  69. package/dist/context/copilot-context.mjs +1 -1
  70. package/dist/context/index.d.ts +1 -1
  71. package/dist/context/index.js +1 -1
  72. package/dist/context/index.js.map +1 -1
  73. package/dist/context/index.mjs +6 -6
  74. package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-ec77e921.d.ts} +3 -3
  75. package/dist/hooks/index.d.ts +1 -1
  76. package/dist/hooks/index.js +206 -164
  77. package/dist/hooks/index.js.map +1 -1
  78. package/dist/hooks/index.mjs +32 -31
  79. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  80. package/dist/hooks/use-agent-nodename.js +56 -0
  81. package/dist/hooks/use-agent-nodename.js.map +1 -0
  82. package/dist/hooks/use-agent-nodename.mjs +8 -0
  83. package/dist/hooks/use-agent-nodename.mjs.map +1 -0
  84. package/dist/hooks/use-coagent-state-render-bridge.js +8 -5
  85. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
  86. package/dist/hooks/use-coagent-state-render-bridge.mjs +3 -3
  87. package/dist/hooks/use-coagent-state-render.js +1 -1
  88. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  89. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  90. package/dist/hooks/use-coagent.js +58 -21
  91. package/dist/hooks/use-coagent.js.map +1 -1
  92. package/dist/hooks/use-coagent.mjs +2 -1
  93. package/dist/hooks/use-configure-chat-suggestions.js +13 -144
  94. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -1
  95. package/dist/hooks/use-configure-chat-suggestions.mjs +1 -6
  96. package/dist/hooks/use-copilot-action.js +5 -1
  97. package/dist/hooks/use-copilot-action.js.map +1 -1
  98. package/dist/hooks/use-copilot-action.mjs +2 -2
  99. package/dist/hooks/use-copilot-additional-instructions.js +1 -1
  100. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  101. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  102. package/dist/hooks/use-copilot-authenticated-action.js +6 -2
  103. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  104. package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
  105. package/dist/hooks/use-copilot-chat-headless_c.js +124 -91
  106. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  107. package/dist/hooks/use-copilot-chat-headless_c.mjs +9 -8
  108. package/dist/hooks/use-copilot-chat.js +122 -89
  109. package/dist/hooks/use-copilot-chat.js.map +1 -1
  110. package/dist/hooks/use-copilot-chat.mjs +9 -8
  111. package/dist/hooks/use-copilot-chat_internal.d.ts +1 -1
  112. package/dist/hooks/use-copilot-chat_internal.js +122 -89
  113. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  114. package/dist/hooks/use-copilot-chat_internal.mjs +8 -7
  115. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  116. package/dist/hooks/use-copilot-readable.js +1 -0
  117. package/dist/hooks/use-copilot-readable.js.map +1 -1
  118. package/dist/hooks/use-copilot-readable.mjs +1 -1
  119. package/dist/hooks/use-default-tool.js +5 -1
  120. package/dist/hooks/use-default-tool.js.map +1 -1
  121. package/dist/hooks/use-default-tool.mjs +3 -3
  122. package/dist/hooks/use-frontend-tool.js +5 -1
  123. package/dist/hooks/use-frontend-tool.js.map +1 -1
  124. package/dist/hooks/use-frontend-tool.mjs +1 -1
  125. package/dist/hooks/use-langgraph-interrupt-render.js +77 -13
  126. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  127. package/dist/hooks/use-langgraph-interrupt-render.mjs +4 -3
  128. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  129. package/dist/hooks/use-langgraph-interrupt.js +3 -3
  130. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  131. package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
  132. package/dist/hooks/use-make-copilot-document-readable.js +1 -1
  133. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  134. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  135. package/dist/index.d.ts +1 -1
  136. package/dist/index.js +225 -191
  137. package/dist/index.js.map +1 -1
  138. package/dist/index.mjs +56 -55
  139. package/dist/lib/copilot-task.d.ts +1 -1
  140. package/dist/lib/copilot-task.js.map +1 -1
  141. package/dist/lib/copilot-task.mjs +15 -15
  142. package/dist/lib/index.d.ts +1 -1
  143. package/dist/lib/index.js.map +1 -1
  144. package/dist/lib/index.mjs +15 -15
  145. package/dist/types/index.d.ts +1 -1
  146. package/dist/types/interrupt-action.d.ts +1 -1
  147. package/dist/types/interrupt-action.js.map +1 -1
  148. package/dist/utils/index.mjs +3 -3
  149. package/dist/v2/index.css +4 -0
  150. package/dist/v2/index.css.map +1 -0
  151. package/dist/v2/index.js.map +1 -1
  152. package/dist/v2/index.mjs +2 -0
  153. package/dist/v2/index.mjs.map +1 -1
  154. package/jest.config.js +12 -0
  155. package/package.json +12 -9
  156. package/src/components/CopilotListeners.tsx +1 -2
  157. package/src/components/copilot-provider/copilot-messages.tsx +0 -41
  158. package/src/components/copilot-provider/copilotkit.tsx +31 -31
  159. package/src/context/copilot-context.tsx +2 -2
  160. package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
  161. package/src/hooks/use-agent-nodename.ts +30 -0
  162. package/src/hooks/use-coagent-state-render-bridge.tsx +22 -22
  163. package/src/hooks/use-coagent.ts +22 -13
  164. package/src/hooks/use-configure-chat-suggestions.tsx +8 -7
  165. package/src/hooks/use-copilot-chat_internal.ts +44 -42
  166. package/src/hooks/use-copilot-readable.ts +2 -1
  167. package/src/hooks/use-frontend-tool.ts +10 -2
  168. package/src/hooks/use-langgraph-interrupt-render.ts +25 -7
  169. package/src/hooks/use-langgraph-interrupt.ts +2 -3
  170. package/src/types/interrupt-action.ts +2 -5
  171. package/src/v2/index.ts +2 -0
  172. package/tsup.config.ts +1 -1
  173. package/dist/chunk-24SCZAB4.mjs.map +0 -1
  174. package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
  175. package/dist/chunk-7BYHZLPL.mjs.map +0 -1
  176. package/dist/chunk-CB7CRBDG.mjs.map +0 -1
  177. package/dist/chunk-DCHSCK62.mjs.map +0 -1
  178. package/dist/chunk-NG26QEGF.mjs.map +0 -1
  179. package/dist/chunk-NROJOTQP.mjs.map +0 -1
  180. package/dist/chunk-R4MR43UQ.mjs.map +0 -1
  181. package/dist/chunk-UJBV5GAG.mjs.map +0 -1
  182. /package/dist/{chunk-3GURHDG7.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
  183. /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
  184. /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
  185. /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-AMUONDZ2.mjs.map} +0 -0
  186. /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
  187. /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-IUNU4CUG.mjs.map} +0 -0
  188. /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
  189. /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-SHHPDZUK.mjs.map} +0 -0
  190. /package/dist/{chunk-LHERIF3L.mjs.map → chunk-SNON4QA6.mjs.map} +0 -0
  191. /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
  192. /package/dist/{chunk-3R423LZT.mjs.map → chunk-XFXT2VNX.mjs.map} +0 -0
  193. /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
  194. /package/src/v2/{styles.css → index.css} +0 -0
package/dist/index.js CHANGED
@@ -198,7 +198,7 @@ var emptyCopilotContext = {
198
198
  interruptEventQueue: {},
199
199
  addInterruptEvent: () => {
200
200
  },
201
- removeInterruptEvent: () => {
201
+ resolveInterruptEvent: () => {
202
202
  },
203
203
  onError: () => {
204
204
  },
@@ -2447,6 +2447,8 @@ function useThreads() {
2447
2447
  // src/hooks/use-coagent-state-render-bridge.tsx
2448
2448
  var import_shared10 = require("@copilotkit/shared");
2449
2449
  function getStateWithoutConstantKeys(state) {
2450
+ if (!state)
2451
+ return {};
2450
2452
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
2451
2453
  return stateWithoutConstantKeys;
2452
2454
  }
@@ -2493,9 +2495,6 @@ function useCoagentStateRenderBridge(agentId, props) {
2493
2495
  unsubscribe();
2494
2496
  };
2495
2497
  }, [agentId, nodeName]);
2496
- if (messageIndexInRun !== 0) {
2497
- return null;
2498
- }
2499
2498
  const getStateRender = (0, import_react14.useCallback)(
2500
2499
  (messageId) => {
2501
2500
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
@@ -2523,7 +2522,7 @@ function useCoagentStateRenderBridge(agentId, props) {
2523
2522
  return canRender;
2524
2523
  }
2525
2524
  const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
2526
- (c) => c.stateRenderId === stateRenderId && (0, import_shared10.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared10.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
2525
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared10.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared10.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
2527
2526
  );
2528
2527
  if (renderClaimedByOtherMessage) {
2529
2528
  if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
@@ -2540,6 +2539,9 @@ function useCoagentStateRenderBridge(agentId, props) {
2540
2539
  };
2541
2540
  return (0, import_react14.useMemo)(() => {
2542
2541
  var _a2, _b, _c;
2542
+ if (messageIndexInRun !== 0) {
2543
+ return null;
2544
+ }
2543
2545
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
2544
2546
  if (!stateRender || !stateRenderId) {
2545
2547
  return null;
@@ -2586,7 +2588,8 @@ function useCoagentStateRenderBridge(agentId, props) {
2586
2588
  agent == null ? void 0 : agent.isRunning,
2587
2589
  nodeName,
2588
2590
  effectiveRunId,
2589
- message.id
2591
+ message.id,
2592
+ messageIndexInRun
2590
2593
  ]);
2591
2594
  }
2592
2595
  function CoAgentStateRenderBridge(props) {
@@ -2631,11 +2634,9 @@ var usePredictStateSubscription = (agent) => {
2631
2634
  }, [agent, getSubscriber]);
2632
2635
  };
2633
2636
  function CopilotListeners() {
2634
- var _a, _b;
2635
2637
  const { copilotkit } = (0, import_react16.useCopilotKit)();
2636
- const { agentSession } = useCopilotContext();
2637
2638
  const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
2638
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
2639
+ const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
2639
2640
  const { setBannerError } = useToast();
2640
2641
  const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
2641
2642
  usePredictStateSubscription(agent);
@@ -2660,15 +2661,7 @@ function CopilotKit(_a) {
2660
2661
  const enabled = shouldShowDevConsole(props.showDevConsole);
2661
2662
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
2662
2663
  const renderArr = (0, import_react17.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
2663
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2664
- import_react18.CopilotKitProvider,
2665
- {
2666
- runtimeUrl: props.runtimeUrl,
2667
- renderCustomMessages: renderArr,
2668
- useSingleEndpoint: true,
2669
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
2670
- }
2671
- ) }) }) });
2664
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react18.CopilotKitProvider, __spreadProps(__spreadValues({}, props), { renderCustomMessages: renderArr, useSingleEndpoint: true, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) })) }) }) });
2672
2665
  }
2673
2666
  function CopilotKitInternal(cpkProps) {
2674
2667
  var _b;
@@ -2906,20 +2899,17 @@ ${nonDocumentStrings}`;
2906
2899
  const chatAbortControllerRef = (0, import_react17.useRef)(null);
2907
2900
  const showDevConsole = shouldShowDevConsole(props.showDevConsole);
2908
2901
  const [interruptActions, _setInterruptActions] = (0, import_react17.useState)({});
2909
- const setInterruptAction = (0, import_react17.useCallback)(
2910
- (threadId2, action) => {
2911
- _setInterruptActions((prev) => {
2912
- var _a2;
2913
- if (action == null || !action.id) {
2914
- return prev;
2915
- }
2916
- return __spreadProps(__spreadValues({}, prev), {
2917
- [action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
2918
- });
2902
+ const setInterruptAction = (0, import_react17.useCallback)((action) => {
2903
+ _setInterruptActions((prev) => {
2904
+ var _a2;
2905
+ if (action == null || !action.id) {
2906
+ return prev;
2907
+ }
2908
+ return __spreadProps(__spreadValues({}, prev), {
2909
+ [action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
2919
2910
  });
2920
- },
2921
- []
2922
- );
2911
+ });
2912
+ }, []);
2923
2913
  const removeInterruptAction = (0, import_react17.useCallback)((actionId) => {
2924
2914
  _setInterruptActions((prev) => {
2925
2915
  const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
@@ -2935,14 +2925,19 @@ ${nonDocumentStrings}`;
2935
2925
  });
2936
2926
  });
2937
2927
  }, []);
2938
- const removeInterruptEvent = (0, import_react17.useCallback)((threadId2, eventId) => {
2939
- setInterruptEventQueue((prev) => {
2940
- const threadQueue = prev[threadId2] || [];
2941
- return __spreadProps(__spreadValues({}, prev), {
2942
- [threadId2]: threadQueue.filter((event) => event.eventId !== eventId)
2928
+ const resolveInterruptEvent = (0, import_react17.useCallback)(
2929
+ (threadId2, eventId, response) => {
2930
+ setInterruptEventQueue((prev) => {
2931
+ const threadQueue = prev[threadId2] || [];
2932
+ return __spreadProps(__spreadValues({}, prev), {
2933
+ [threadId2]: threadQueue.map(
2934
+ (queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
2935
+ )
2936
+ });
2943
2937
  });
2944
- });
2945
- }, []);
2938
+ },
2939
+ []
2940
+ );
2946
2941
  const memoizedChildren = (0, import_react17.useMemo)(() => children, [children]);
2947
2942
  const [bannerError, setBannerError] = (0, import_react17.useState)(null);
2948
2943
  const agentLock = (0, import_react17.useMemo)(() => {
@@ -3005,7 +3000,7 @@ ${nonDocumentStrings}`;
3005
3000
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3006
3001
  import_react18.CopilotChatConfigurationProvider,
3007
3002
  {
3008
- agentId: (_b = agentSession == null ? void 0 : agentSession.agentName) != null ? _b : "default",
3003
+ agentId: (_b = props.agent) != null ? _b : "default",
3009
3004
  threadId,
3010
3005
  children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3011
3006
  CopilotContext.Provider,
@@ -3060,7 +3055,7 @@ ${nonDocumentStrings}`;
3060
3055
  removeInterruptAction,
3061
3056
  interruptEventQueue,
3062
3057
  addInterruptEvent,
3063
- removeInterruptEvent,
3058
+ resolveInterruptEvent,
3064
3059
  bannerError,
3065
3060
  setBannerError,
3066
3061
  onError: handleErrors,
@@ -3137,28 +3132,64 @@ function validateProps(props) {
3137
3132
  }
3138
3133
 
3139
3134
  // src/hooks/use-copilot-chat_internal.ts
3140
- var import_react24 = require("react");
3135
+ var import_react27 = require("react");
3141
3136
  var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
3142
3137
 
3143
3138
  // src/hooks/use-langgraph-interrupt-render.ts
3144
- var import_react19 = __toESM(require("react"));
3139
+ var import_react21 = __toESM(require("react"));
3145
3140
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
3146
3141
  var import_shared14 = require("@copilotkit/shared");
3142
+
3143
+ // src/hooks/use-agent-nodename.ts
3144
+ var import_react19 = require("react");
3145
+ var import_react20 = require("@copilotkitnext/react");
3146
+ function useAgentNodeName(agentName) {
3147
+ const { agent } = (0, import_react20.useAgent)({ agentId: agentName });
3148
+ const nodeNameRef = (0, import_react19.useRef)("start");
3149
+ (0, import_react19.useEffect)(() => {
3150
+ if (!agent)
3151
+ return;
3152
+ const subscriber = {
3153
+ onStepStartedEvent: ({ event }) => {
3154
+ nodeNameRef.current = event.stepName;
3155
+ },
3156
+ onRunStartedEvent: () => {
3157
+ nodeNameRef.current = "start";
3158
+ },
3159
+ onRunFinishedEvent: () => {
3160
+ nodeNameRef.current = "end";
3161
+ }
3162
+ };
3163
+ const subscription = agent.subscribe(subscriber);
3164
+ return () => {
3165
+ subscription.unsubscribe();
3166
+ };
3167
+ }, [agent]);
3168
+ return nodeNameRef.current;
3169
+ }
3170
+
3171
+ // src/hooks/use-langgraph-interrupt-render.ts
3172
+ var import_react22 = require("@copilotkitnext/react");
3147
3173
  var InterruptRenderer = ({ event, result, render, resolve }) => {
3148
3174
  return render({ event, result, resolve });
3149
3175
  };
3150
3176
  function useLangGraphInterruptRender(agent) {
3177
+ var _a;
3151
3178
  const {
3152
3179
  interruptActions,
3153
3180
  agentSession,
3154
3181
  threadId,
3155
3182
  interruptEventQueue,
3156
3183
  addInterruptEvent,
3157
- removeInterruptEvent
3184
+ resolveInterruptEvent
3158
3185
  } = useCopilotContext();
3159
- (0, import_react19.useEffect)(() => {
3186
+ const existingConfig = (0, import_react22.useCopilotChatConfiguration)();
3187
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
3188
+ const nodeName = useAgentNodeName(resolvedAgentId);
3189
+ (0, import_react21.useEffect)(() => {
3160
3190
  if (!agent)
3161
3191
  return;
3192
+ let localInterrupt = null;
3162
3193
  const subscriber = {
3163
3194
  onCustomEvent: ({ event }) => {
3164
3195
  if (event.name === "on_interrupt") {
@@ -3167,12 +3198,21 @@ function useLangGraphInterruptRender(agent) {
3167
3198
  type: event.type,
3168
3199
  value: (0, import_shared14.parseJson)(event.value, event.value)
3169
3200
  };
3170
- const eventId = (0, import_shared14.dataToUUID)(JSON.stringify(eventData), "interruptEvents");
3171
- addInterruptEvent({
3201
+ const eventId = (0, import_shared14.dataToUUID)(eventData, "interruptEvents");
3202
+ localInterrupt = {
3172
3203
  eventId,
3173
3204
  threadId,
3174
3205
  event: eventData
3175
- });
3206
+ };
3207
+ }
3208
+ },
3209
+ onRunStartedEvent: () => {
3210
+ localInterrupt = null;
3211
+ },
3212
+ onRunFinalized: () => {
3213
+ if (localInterrupt) {
3214
+ addInterruptEvent(localInterrupt);
3215
+ localInterrupt = null;
3176
3216
  }
3177
3217
  }
3178
3218
  };
@@ -3181,7 +3221,7 @@ function useLangGraphInterruptRender(agent) {
3181
3221
  unsubscribe();
3182
3222
  };
3183
3223
  }, [agent, threadId]);
3184
- const handleResolve = (0, import_react19.useCallback)(
3224
+ const handleResolve = (0, import_react21.useCallback)(
3185
3225
  (eventId, response) => {
3186
3226
  agent == null ? void 0 : agent.runAgent({
3187
3227
  forwardedProps: {
@@ -3190,15 +3230,15 @@ function useLangGraphInterruptRender(agent) {
3190
3230
  }
3191
3231
  }
3192
3232
  });
3193
- removeInterruptEvent(threadId, eventId);
3233
+ resolveInterruptEvent(threadId, eventId, response != null ? response : "");
3194
3234
  },
3195
3235
  // eslint-disable-next-line react-hooks/exhaustive-deps
3196
3236
  [agent, threadId]
3197
3237
  );
3198
- return (0, import_react19.useMemo)(() => {
3238
+ return (0, import_react21.useMemo)(() => {
3199
3239
  const eventQueue = interruptEventQueue[threadId] || [];
3200
3240
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
3201
- if (!currentQueuedEvent)
3241
+ if (!currentQueuedEvent || !agentSession)
3202
3242
  return null;
3203
3243
  const allActions = Object.values(interruptActions);
3204
3244
  const matchingAction = allActions.find((action) => {
@@ -3206,7 +3246,9 @@ function useLangGraphInterruptRender(agent) {
3206
3246
  return true;
3207
3247
  return action.enabled({
3208
3248
  eventValue: currentQueuedEvent.event.value,
3209
- agentMetadata: agentSession
3249
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
3250
+ nodeName
3251
+ })
3210
3252
  });
3211
3253
  });
3212
3254
  if (!matchingAction)
@@ -3224,7 +3266,7 @@ function useLangGraphInterruptRender(agent) {
3224
3266
  }
3225
3267
  if (!render)
3226
3268
  return null;
3227
- return import_react19.default.createElement(InterruptRenderer, {
3269
+ return import_react21.default.createElement(InterruptRenderer, {
3228
3270
  event: currentQueuedEvent.event,
3229
3271
  result,
3230
3272
  render,
@@ -3234,14 +3276,14 @@ function useLangGraphInterruptRender(agent) {
3234
3276
  }
3235
3277
 
3236
3278
  // src/hooks/use-copilot-chat_internal.ts
3237
- var import_react25 = require("@copilotkitnext/react");
3279
+ var import_react28 = require("@copilotkitnext/react");
3238
3280
 
3239
3281
  // src/hooks/use-lazy-tool-renderer.tsx
3240
- var import_react20 = require("@copilotkitnext/react");
3241
- var import_react21 = require("react");
3282
+ var import_react23 = require("@copilotkitnext/react");
3283
+ var import_react24 = require("react");
3242
3284
  function useLazyToolRenderer() {
3243
- const renderToolCall = (0, import_react20.useRenderToolCall)();
3244
- return (0, import_react21.useCallback)(
3285
+ const renderToolCall = (0, import_react23.useRenderToolCall)();
3286
+ return (0, import_react24.useCallback)(
3245
3287
  (message, messages) => {
3246
3288
  var _a;
3247
3289
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -3262,34 +3304,36 @@ function useLazyToolRenderer() {
3262
3304
  }
3263
3305
 
3264
3306
  // src/hooks/use-configure-chat-suggestions.tsx
3265
- var import_react22 = require("@copilotkitnext/react");
3266
- var import_react23 = require("react");
3307
+ var import_react25 = require("@copilotkitnext/react");
3308
+ var import_react26 = require("react");
3267
3309
  function useConfigureChatSuggestions(config, dependencies = []) {
3268
- const { agentSession } = useCopilotContext();
3269
- const { copilotkit } = (0, import_react22.useCopilotKit)();
3310
+ var _a;
3311
+ const existingConfig = (0, import_react25.useCopilotChatConfiguration)();
3312
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
3313
+ const { copilotkit } = (0, import_react25.useCopilotKit)();
3270
3314
  const available = config.available === "enabled" ? "always" : config.available;
3271
3315
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
3272
3316
  available,
3273
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
3317
+ consumerAgentId: resolvedAgentId
3274
3318
  // Use chatConfig.agentId here
3275
3319
  });
3276
- (0, import_react22.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
3277
- const result = (0, import_react22.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
3278
- (0, import_react23.useEffect)(() => {
3320
+ (0, import_react25.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
3321
+ const result = (0, import_react25.useSuggestions)({ agentId: resolvedAgentId });
3322
+ (0, import_react26.useEffect)(() => {
3279
3323
  if (finalSuggestionConfig.available === "disabled")
3280
3324
  return;
3281
3325
  const subscription = copilotkit.subscribe({
3282
3326
  onAgentsChanged: () => {
3283
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
3327
+ const agent = copilotkit.getAgent(resolvedAgentId);
3284
3328
  if (agent && !agent.isRunning && !result.suggestions.length) {
3285
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
3329
+ copilotkit.reloadSuggestions(resolvedAgentId);
3286
3330
  }
3287
3331
  }
3288
3332
  });
3289
3333
  return () => {
3290
3334
  subscription.unsubscribe();
3291
3335
  };
3292
- }, []);
3336
+ }, [resolvedAgentId]);
3293
3337
  return result;
3294
3338
  }
3295
3339
 
@@ -3719,15 +3763,15 @@ function useConfigureSuggestions2(suggestions) {
3719
3763
  function useCopilotChatInternal({
3720
3764
  suggestions
3721
3765
  } = {}) {
3722
- var _a, _b, _c, _d;
3723
- const { copilotkit } = (0, import_react25.useCopilotKit)();
3766
+ var _a, _b, _c;
3767
+ const { copilotkit } = (0, import_react28.useCopilotKit)();
3724
3768
  const { threadId, agentSession } = useCopilotContext();
3725
- const existingConfig = (0, import_react25.useCopilotChatConfiguration)();
3726
- const [agentAvailable, setAgentAvailable] = (0, import_react24.useState)(false);
3769
+ const existingConfig = (0, import_react28.useCopilotChatConfiguration)();
3770
+ const [agentAvailable, setAgentAvailable] = (0, import_react27.useState)(false);
3727
3771
  useConfigureSuggestions2(suggestions);
3728
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
3729
- const { agent } = (0, import_react25.useAgent)({ agentId: resolvedAgentId });
3730
- (0, import_react24.useEffect)(() => {
3772
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
3773
+ const { agent } = (0, import_react28.useAgent)({ agentId: resolvedAgentId });
3774
+ (0, import_react27.useEffect)(() => {
3731
3775
  const connect = (agent2) => __async(this, null, function* () {
3732
3776
  setAgentAvailable(false);
3733
3777
  try {
@@ -3752,7 +3796,7 @@ function useCopilotChatInternal({
3752
3796
  agent == null ? void 0 : agent.setMessages([]);
3753
3797
  agent == null ? void 0 : agent.setState(null);
3754
3798
  };
3755
- const deleteMessage = (0, import_react24.useCallback)(
3799
+ const deleteMessage = (0, import_react27.useCallback)(
3756
3800
  (messageId) => {
3757
3801
  var _a2;
3758
3802
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -3763,13 +3807,13 @@ function useCopilotChatInternal({
3763
3807
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
3764
3808
  );
3765
3809
  const latestDelete = useUpdatedRef(deleteMessage);
3766
- const latestDeleteFunc = (0, import_react24.useCallback)(
3810
+ const latestDeleteFunc = (0, import_react27.useCallback)(
3767
3811
  (messageId) => {
3768
3812
  return latestDelete.current(messageId);
3769
3813
  },
3770
3814
  [latestDelete]
3771
3815
  );
3772
- const currentSuggestions = (0, import_react25.useSuggestions)({ agentId: resolvedAgentId });
3816
+ const currentSuggestions = (0, import_react28.useSuggestions)({ agentId: resolvedAgentId });
3773
3817
  const reload = useAsyncCallback(
3774
3818
  (reloadMessageId) => __async(this, null, function* () {
3775
3819
  var _a2;
@@ -3837,7 +3881,7 @@ function useCopilotChatInternal({
3837
3881
  [latestSendMessageFunc]
3838
3882
  );
3839
3883
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
3840
- const latestSetMessagesFunc = (0, import_react24.useCallback)(
3884
+ const latestSetMessagesFunc = (0, import_react27.useCallback)(
3841
3885
  (messages) => {
3842
3886
  var _a2, _b2;
3843
3887
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -3855,24 +3899,24 @@ function useCopilotChatInternal({
3855
3899
  [latestReload]
3856
3900
  );
3857
3901
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
3858
- const latestStopFunc = (0, import_react24.useCallback)(() => {
3902
+ const latestStopFunc = (0, import_react27.useCallback)(() => {
3859
3903
  var _a2;
3860
3904
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
3861
3905
  }, [latestStop]);
3862
3906
  const latestReset = useUpdatedRef(reset);
3863
- const latestResetFunc = (0, import_react24.useCallback)(() => {
3907
+ const latestResetFunc = (0, import_react27.useCallback)(() => {
3864
3908
  return latestReset.current();
3865
3909
  }, [latestReset]);
3866
3910
  const lazyToolRendered = useLazyToolRenderer();
3867
- const renderCustomMessage = (0, import_react25.useRenderCustomMessages)();
3911
+ const renderCustomMessage = (0, import_react28.useRenderCustomMessages)();
3868
3912
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
3869
3913
  copilotkit,
3870
3914
  agent,
3871
3915
  agentId: resolvedAgentId,
3872
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
3916
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
3873
3917
  });
3874
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
3875
- const resolvedMessages = (0, import_react24.useMemo)(() => {
3918
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
3919
+ const resolvedMessages = (0, import_react27.useMemo)(() => {
3876
3920
  let processedMessages = allMessages.map((message) => {
3877
3921
  if (message.role !== "assistant") {
3878
3922
  return message;
@@ -3900,31 +3944,13 @@ function useCopilotChatInternal({
3900
3944
  return message;
3901
3945
  });
3902
3946
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
3903
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
3904
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
3905
- const placeholderMessage = {
3906
- id: placeholderId,
3907
- role: "assistant",
3908
- content: "",
3909
- name: "coagent-state-render"
3910
- };
3911
- processedMessages = [
3912
- ...processedMessages,
3913
- __spreadProps(__spreadValues({}, placeholderMessage), {
3914
- generativeUI: () => legacyCustomMessageRenderer({
3915
- message: placeholderMessage,
3916
- position: "before"
3917
- })
3918
- })
3919
- ];
3920
- }
3921
3947
  return processedMessages;
3922
3948
  }, [
3923
3949
  agent == null ? void 0 : agent.messages,
3924
3950
  lazyToolRendered,
3925
3951
  allMessages,
3926
3952
  renderCustomMessage,
3927
- legacyCustomMessageRenderer,
3953
+ // legacyCustomMessageRenderer,
3928
3954
  resolvedAgentId
3929
3955
  ]);
3930
3956
  return {
@@ -3936,7 +3962,7 @@ function useCopilotChatInternal({
3936
3962
  stopGeneration: latestStopFunc,
3937
3963
  reset: latestResetFunc,
3938
3964
  deleteMessage: latestDeleteFunc,
3939
- isAvailable: !agentAvailable,
3965
+ isAvailable: agentAvailable,
3940
3966
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
3941
3967
  // mcpServers,
3942
3968
  // setMcpServers,
@@ -3953,8 +3979,8 @@ function useCopilotChatInternal({
3953
3979
  };
3954
3980
  }
3955
3981
  function useUpdatedRef(value) {
3956
- const ref = (0, import_react24.useRef)(value);
3957
- (0, import_react24.useEffect)(() => {
3982
+ const ref = (0, import_react27.useRef)(value);
3983
+ (0, import_react27.useEffect)(() => {
3958
3984
  ref.current = value;
3959
3985
  }, [value]);
3960
3986
  return ref;
@@ -3965,20 +3991,19 @@ function useLegacyCoagentRenderer({
3965
3991
  agentId,
3966
3992
  threadId
3967
3993
  }) {
3968
- return (0, import_react24.useMemo)(() => {
3994
+ return (0, import_react27.useMemo)(() => {
3969
3995
  if (!copilotkit || !agent) {
3970
3996
  return null;
3971
3997
  }
3972
3998
  return ({ message, position }) => {
3973
3999
  var _a;
3974
4000
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
3975
- const existingRunId = copilotkit.getRunIdForMessage(
3976
- agentId,
3977
- effectiveThreadId,
3978
- message.id
3979
- );
4001
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
3980
4002
  const runId = existingRunId || `pending:${message.id}`;
3981
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
4003
+ const messageIndex = Math.max(
4004
+ agent.messages.findIndex((msg) => msg.id === message.id),
4005
+ 0
4006
+ );
3982
4007
  const bridgeProps = {
3983
4008
  message,
3984
4009
  position,
@@ -3989,7 +4014,7 @@ function useLegacyCoagentRenderer({
3989
4014
  agentId,
3990
4015
  stateSnapshot: message.state
3991
4016
  };
3992
- return (0, import_react24.createElement)(CoAgentStateRenderBridge, bridgeProps);
4017
+ return (0, import_react27.createElement)(CoAgentStateRenderBridge, bridgeProps);
3993
4018
  };
3994
4019
  }, [agent, agentId, copilotkit, threadId]);
3995
4020
  }
@@ -4023,7 +4048,7 @@ function useCopilotChat(options = {}) {
4023
4048
  }
4024
4049
 
4025
4050
  // src/hooks/use-copilot-chat-headless_c.ts
4026
- var import_react26 = require("react");
4051
+ var import_react29 = require("react");
4027
4052
  var import_shared15 = require("@copilotkit/shared");
4028
4053
  var createNonFunctionalReturn = () => ({
4029
4054
  visibleMessages: [],
@@ -4064,7 +4089,7 @@ function useCopilotChatHeadless_c(options = {}) {
4064
4089
  const { copilotApiConfig, setBannerError } = useCopilotContext();
4065
4090
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
4066
4091
  const internalResult = useCopilotChatInternal(options);
4067
- (0, import_react26.useEffect)(() => {
4092
+ (0, import_react29.useEffect)(() => {
4068
4093
  if (!hasPublicApiKey) {
4069
4094
  setBannerError(
4070
4095
  new import_shared15.CopilotKitError({
@@ -4089,13 +4114,13 @@ function useCopilotChatHeadless_c(options = {}) {
4089
4114
  }
4090
4115
 
4091
4116
  // src/hooks/use-copilot-action.ts
4092
- var import_react33 = require("react");
4117
+ var import_react36 = require("react");
4093
4118
 
4094
4119
  // src/hooks/use-frontend-tool.ts
4095
- var import_react27 = __toESM(require("react"));
4120
+ var import_react30 = __toESM(require("react"));
4096
4121
  var import_shared16 = require("@copilotkit/shared");
4097
4122
  var import_shared17 = require("@copilotkit/shared");
4098
- var import_react28 = require("@copilotkitnext/react");
4123
+ var import_react31 = require("@copilotkitnext/react");
4099
4124
  function useFrontendTool(tool, dependencies) {
4100
4125
  const { name, description, parameters, render, followUp } = tool;
4101
4126
  const zodParameters = (0, import_shared16.getZodParameters)(parameters);
@@ -4105,7 +4130,11 @@ function useFrontendTool(tool, dependencies) {
4105
4130
  }
4106
4131
  if (typeof render === "string") {
4107
4132
  const staticRender = render;
4108
- return () => import_react27.default.createElement(import_react27.default.Fragment, null, staticRender);
4133
+ return () => import_react30.default.createElement(
4134
+ import_react30.default.Fragment,
4135
+ null,
4136
+ staticRender
4137
+ );
4109
4138
  }
4110
4139
  return (args) => {
4111
4140
  const renderArgs = __spreadProps(__spreadValues({}, args), {
@@ -4113,12 +4142,12 @@ function useFrontendTool(tool, dependencies) {
4113
4142
  });
4114
4143
  const rendered = render(renderArgs);
4115
4144
  if (typeof rendered === "string") {
4116
- return import_react27.default.createElement(import_react27.default.Fragment, null, rendered);
4145
+ return import_react30.default.createElement(import_react30.default.Fragment, null, rendered);
4117
4146
  }
4118
4147
  return rendered != null ? rendered : null;
4119
4148
  };
4120
4149
  })();
4121
- (0, import_react28.useFrontendTool)({
4150
+ (0, import_react31.useFrontendTool)({
4122
4151
  name,
4123
4152
  description,
4124
4153
  parameters: zodParameters,
@@ -4130,23 +4159,23 @@ function useFrontendTool(tool, dependencies) {
4130
4159
 
4131
4160
  // src/hooks/use-render-tool-call.ts
4132
4161
  var import_shared18 = require("@copilotkit/shared");
4133
- var import_react29 = require("react");
4134
- var import_react30 = require("@copilotkitnext/react");
4162
+ var import_react32 = require("react");
4163
+ var import_react33 = require("@copilotkitnext/react");
4135
4164
  var import_shared19 = require("@copilotkit/shared");
4136
4165
  function useRenderToolCall2(tool, dependencies) {
4137
- const { copilotkit } = (0, import_react30.useCopilotKit)();
4138
- const hasAddedRef = (0, import_react29.useRef)(false);
4139
- (0, import_react29.useEffect)(() => {
4166
+ const { copilotkit } = (0, import_react33.useCopilotKit)();
4167
+ const hasAddedRef = (0, import_react32.useRef)(false);
4168
+ (0, import_react32.useEffect)(() => {
4140
4169
  const { name, parameters, render } = tool;
4141
4170
  const zodParameters = (0, import_shared18.getZodParameters)(parameters);
4142
- const renderToolCall = name === "*" ? (0, import_react30.defineToolCallRenderer)({
4171
+ const renderToolCall = name === "*" ? (0, import_react33.defineToolCallRenderer)({
4143
4172
  name: "*",
4144
4173
  render: (args) => {
4145
4174
  return render(__spreadProps(__spreadValues({}, args), {
4146
4175
  result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
4147
4176
  }));
4148
4177
  }
4149
- }) : (0, import_react30.defineToolCallRenderer)({
4178
+ }) : (0, import_react33.defineToolCallRenderer)({
4150
4179
  name,
4151
4180
  args: zodParameters,
4152
4181
  render: (args) => {
@@ -4175,18 +4204,18 @@ function useRenderToolCall2(tool, dependencies) {
4175
4204
 
4176
4205
  // src/hooks/use-human-in-the-loop.ts
4177
4206
  var import_shared20 = require("@copilotkit/shared");
4178
- var import_react31 = require("@copilotkitnext/react");
4207
+ var import_react34 = require("@copilotkitnext/react");
4179
4208
  var import_core = require("@copilotkitnext/core");
4180
- var import_react32 = __toESM(require("react"));
4209
+ var import_react35 = __toESM(require("react"));
4181
4210
  function useHumanInTheLoop(tool, dependencies) {
4182
4211
  const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
4183
4212
  const { name, description, parameters, followUp } = toolRest;
4184
4213
  const zodParameters = (0, import_shared20.getZodParameters)(parameters);
4185
- const renderRef = (0, import_react32.useRef)(null);
4186
- (0, import_react32.useEffect)(() => {
4214
+ const renderRef = (0, import_react35.useRef)(null);
4215
+ (0, import_react35.useEffect)(() => {
4187
4216
  renderRef.current = (args) => {
4188
4217
  if (typeof render === "string") {
4189
- return import_react32.default.createElement(import_react32.default.Fragment, null, render);
4218
+ return import_react35.default.createElement(import_react35.default.Fragment, null, render);
4190
4219
  }
4191
4220
  if (!render) {
4192
4221
  return null;
@@ -4226,12 +4255,12 @@ function useHumanInTheLoop(tool, dependencies) {
4226
4255
  })();
4227
4256
  const rendered = render(renderProps);
4228
4257
  if (typeof rendered === "string") {
4229
- return import_react32.default.createElement(import_react32.default.Fragment, null, rendered);
4258
+ return import_react35.default.createElement(import_react35.default.Fragment, null, rendered);
4230
4259
  }
4231
4260
  return rendered != null ? rendered : null;
4232
4261
  };
4233
4262
  }, [render, ...dependencies != null ? dependencies : []]);
4234
- (0, import_react31.useHumanInTheLoop)({
4263
+ (0, import_react34.useHumanInTheLoop)({
4235
4264
  name,
4236
4265
  description,
4237
4266
  followUp,
@@ -4287,7 +4316,7 @@ function getActionConfig(action) {
4287
4316
  throw new Error("Invalid action configuration");
4288
4317
  }
4289
4318
  function useCopilotAction(action, dependencies) {
4290
- const [initialActionConfig] = (0, import_react33.useState)(getActionConfig(action));
4319
+ const [initialActionConfig] = (0, import_react36.useState)(getActionConfig(action));
4291
4320
  const currentActionConfig = getActionConfig(action);
4292
4321
  if (initialActionConfig.type !== currentActionConfig.type) {
4293
4322
  throw new Error("Action configuration changed between renders");
@@ -4305,14 +4334,14 @@ function useCopilotAction(action, dependencies) {
4305
4334
  }
4306
4335
 
4307
4336
  // src/hooks/use-coagent-state-render.ts
4308
- var import_react34 = require("react");
4337
+ var import_react37 = require("react");
4309
4338
  var import_shared21 = require("@copilotkit/shared");
4310
4339
  function useCoAgentStateRender(action, dependencies) {
4311
- const { chatComponentsCache, availableAgents } = (0, import_react34.useContext)(CopilotContext);
4340
+ const { chatComponentsCache, availableAgents } = (0, import_react37.useContext)(CopilotContext);
4312
4341
  const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
4313
- const idRef = (0, import_react34.useRef)((0, import_shared21.randomId)());
4342
+ const idRef = (0, import_react37.useRef)((0, import_shared21.randomId)());
4314
4343
  const { setBannerError, addToast } = useToast();
4315
- (0, import_react34.useEffect)(() => {
4344
+ (0, import_react37.useEffect)(() => {
4316
4345
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
4317
4346
  const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
4318
4347
  const agentError = new import_shared21.CopilotKitAgentDiscoveryError({
@@ -4333,7 +4362,7 @@ function useCoAgentStateRender(action, dependencies) {
4333
4362
  }
4334
4363
  }
4335
4364
  }
4336
- (0, import_react34.useEffect)(() => {
4365
+ (0, import_react37.useEffect)(() => {
4337
4366
  const currentId = idRef.current;
4338
4367
  const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
4339
4368
  if (id === currentId)
@@ -4357,7 +4386,7 @@ function useCoAgentStateRender(action, dependencies) {
4357
4386
  });
4358
4387
  }
4359
4388
  }, [coAgentStateRenders]);
4360
- (0, import_react34.useEffect)(() => {
4389
+ (0, import_react37.useEffect)(() => {
4361
4390
  setCoAgentStateRender(idRef.current, action);
4362
4391
  if (chatComponentsCache.current !== null && action.render !== void 0) {
4363
4392
  chatComponentsCache.current.coAgentStateRenders[key] = action.render;
@@ -4377,11 +4406,11 @@ function useCoAgentStateRender(action, dependencies) {
4377
4406
  }
4378
4407
 
4379
4408
  // src/hooks/use-make-copilot-document-readable.ts
4380
- var import_react35 = require("react");
4409
+ var import_react38 = require("react");
4381
4410
  function useMakeCopilotDocumentReadable(document2, categories, dependencies = []) {
4382
4411
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
4383
- const idRef = (0, import_react35.useRef)(void 0);
4384
- (0, import_react35.useEffect)(() => {
4412
+ const idRef = (0, import_react38.useRef)(void 0);
4413
+ (0, import_react38.useEffect)(() => {
4385
4414
  const id = addDocumentContext(document2, categories);
4386
4415
  idRef.current = id;
4387
4416
  return () => {
@@ -4392,21 +4421,23 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
4392
4421
  }
4393
4422
 
4394
4423
  // src/hooks/use-copilot-readable.ts
4395
- var import_react36 = require("@copilotkitnext/react");
4424
+ var import_react39 = require("@copilotkitnext/react");
4396
4425
  function useCopilotReadable({ description, value }, dependencies) {
4397
- (0, import_react36.useAgentContext)({
4426
+ (0, import_react39.useAgentContext)({
4398
4427
  description,
4399
4428
  value
4400
4429
  });
4430
+ return;
4401
4431
  }
4402
4432
 
4403
4433
  // src/hooks/use-coagent.ts
4404
- var import_react37 = require("react");
4405
- var import_react38 = require("@copilotkitnext/react");
4434
+ var import_react40 = require("react");
4435
+ var import_react41 = require("@copilotkitnext/react");
4406
4436
  function useCoAgent(options) {
4407
- const { agent } = (0, import_react38.useAgent)({ agentId: options.name });
4408
- const nodeNameRef = (0, import_react37.useRef)("start");
4409
- const handleStateUpdate = (0, import_react37.useCallback)(
4437
+ const { agent } = (0, import_react41.useAgent)({ agentId: options.name });
4438
+ const { copilotkit } = (0, import_react41.useCopilotKit)();
4439
+ const nodeName = useAgentNodeName(options.name);
4440
+ const handleStateUpdate = (0, import_react40.useCallback)(
4410
4441
  (newState) => {
4411
4442
  if (!agent)
4412
4443
  return;
@@ -4419,22 +4450,34 @@ function useCoAgent(options) {
4419
4450
  },
4420
4451
  [agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
4421
4452
  );
4422
- const externalStateStr = (0, import_react37.useMemo)(
4453
+ (0, import_react40.useEffect)(() => {
4454
+ var _a;
4455
+ if (!options.config && !options.configurable)
4456
+ return;
4457
+ let config = (_a = options.config) != null ? _a : {};
4458
+ if (options.configurable) {
4459
+ config = __spreadProps(__spreadValues({}, config), {
4460
+ configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
4461
+ });
4462
+ }
4463
+ copilotkit.setProperties(config);
4464
+ }, [options.config, options.configurable]);
4465
+ const externalStateStr = (0, import_react40.useMemo)(
4423
4466
  () => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
4424
4467
  [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
4425
4468
  );
4426
- (0, import_react37.useEffect)(() => {
4469
+ (0, import_react40.useEffect)(() => {
4427
4470
  if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
4428
4471
  handleStateUpdate(options.state);
4429
4472
  }
4430
4473
  }, [agent, externalStateStr, handleStateUpdate]);
4431
- const hasStateValues = (0, import_react37.useCallback)((value) => {
4474
+ const hasStateValues = (0, import_react40.useCallback)((value) => {
4432
4475
  return Boolean(value && Object.keys(value).length);
4433
4476
  }, []);
4434
- const initialStateRef = (0, import_react37.useRef)(
4477
+ const initialStateRef = (0, import_react40.useRef)(
4435
4478
  isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
4436
4479
  );
4437
- (0, import_react37.useEffect)(() => {
4480
+ (0, import_react40.useEffect)(() => {
4438
4481
  if (isExternalStateManagement(options)) {
4439
4482
  initialStateRef.current = options.state;
4440
4483
  } else if ("initialState" in options) {
@@ -4443,7 +4486,7 @@ function useCoAgent(options) {
4443
4486
  }, [
4444
4487
  isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
4445
4488
  ]);
4446
- (0, import_react37.useEffect)(() => {
4489
+ (0, import_react40.useEffect)(() => {
4447
4490
  if (!agent)
4448
4491
  return;
4449
4492
  const subscriber = {
@@ -4464,15 +4507,6 @@ function useCoAgent(options) {
4464
4507
  if (initialStateRef.current !== void 0) {
4465
4508
  handleStateUpdate(initialStateRef.current);
4466
4509
  }
4467
- },
4468
- onStepStartedEvent: ({ event }) => {
4469
- nodeNameRef.current = event.stepName;
4470
- },
4471
- onRunStartedEvent: () => {
4472
- nodeNameRef.current = "start";
4473
- },
4474
- onRunFinishedEvent: () => {
4475
- nodeNameRef.current = "end";
4476
4510
  }
4477
4511
  };
4478
4512
  const subscription = agent.subscribe(subscriber);
@@ -4480,7 +4514,7 @@ function useCoAgent(options) {
4480
4514
  subscription.unsubscribe();
4481
4515
  };
4482
4516
  }, [agent, handleStateUpdate, hasStateValues]);
4483
- return (0, import_react37.useMemo)(() => {
4517
+ return (0, import_react40.useMemo)(() => {
4484
4518
  var _a, _b, _c;
4485
4519
  if (!agent) {
4486
4520
  const noop = () => {
@@ -4496,7 +4530,7 @@ function useCoAgent(options) {
4496
4530
  );
4497
4531
  return {
4498
4532
  name: options.name,
4499
- nodeName: nodeNameRef.current,
4533
+ nodeName,
4500
4534
  threadId: void 0,
4501
4535
  running: false,
4502
4536
  state: initialState,
@@ -4508,7 +4542,7 @@ function useCoAgent(options) {
4508
4542
  }
4509
4543
  return {
4510
4544
  name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
4511
- nodeName: nodeNameRef.current,
4545
+ nodeName,
4512
4546
  threadId: agent.threadId,
4513
4547
  running: agent.isRunning,
4514
4548
  state: agent.state,
@@ -4536,12 +4570,12 @@ var isExternalStateManagement = (options) => {
4536
4570
 
4537
4571
  // src/hooks/use-copilot-runtime-client.ts
4538
4572
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
4539
- var import_react39 = require("react");
4573
+ var import_react42 = require("react");
4540
4574
  var import_shared22 = require("@copilotkit/shared");
4541
4575
  var useCopilotRuntimeClient = (options) => {
4542
4576
  const { setBannerError } = useToast();
4543
4577
  const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
4544
- const lastStructuredErrorRef = (0, import_react39.useRef)(null);
4578
+ const lastStructuredErrorRef = (0, import_react42.useRef)(null);
4545
4579
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
4546
4580
  try {
4547
4581
  const errorEvent = {
@@ -4567,7 +4601,7 @@ var useCopilotRuntimeClient = (options) => {
4567
4601
  console.error("Error in onError handler:", error2);
4568
4602
  }
4569
4603
  });
4570
- const runtimeClient = (0, import_react39.useMemo)(() => {
4604
+ const runtimeClient = (0, import_react42.useMemo)(() => {
4571
4605
  return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
4572
4606
  handleGQLErrors: (error) => {
4573
4607
  var _a2;
@@ -4646,28 +4680,28 @@ function createStructuredError(gqlError) {
4646
4680
  }
4647
4681
 
4648
4682
  // src/hooks/use-copilot-authenticated-action.ts
4649
- var import_react40 = require("react");
4650
- var import_react41 = __toESM(require("react"));
4683
+ var import_react43 = require("react");
4684
+ var import_react44 = __toESM(require("react"));
4651
4685
  function useCopilotAuthenticatedAction_c(action, dependencies) {
4652
4686
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
4653
- const pendingActionRef = (0, import_react40.useRef)(null);
4654
- const executeAction = (0, import_react40.useCallback)(
4687
+ const pendingActionRef = (0, import_react43.useRef)(null);
4688
+ const executeAction = (0, import_react43.useCallback)(
4655
4689
  (props) => {
4656
4690
  if (typeof action.render === "function") {
4657
4691
  return action.render(props);
4658
4692
  }
4659
- return action.render || import_react41.default.createElement(import_react40.Fragment);
4693
+ return action.render || import_react44.default.createElement(import_react43.Fragment);
4660
4694
  },
4661
4695
  [action]
4662
4696
  );
4663
- const wrappedRender = (0, import_react40.useCallback)(
4697
+ const wrappedRender = (0, import_react43.useCallback)(
4664
4698
  (props) => {
4665
4699
  const isAuthenticated = Object.values(authStates_c || {}).some(
4666
4700
  (state) => state.status === "authenticated"
4667
4701
  );
4668
4702
  if (!isAuthenticated) {
4669
4703
  pendingActionRef.current = props;
4670
- return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react41.default.createElement(authConfig_c.SignInComponent, {
4704
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react44.default.createElement(authConfig_c.SignInComponent, {
4671
4705
  onSignInComplete: (authState) => {
4672
4706
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
4673
4707
  if (pendingActionRef.current) {
@@ -4675,7 +4709,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
4675
4709
  pendingActionRef.current = null;
4676
4710
  }
4677
4711
  }
4678
- }) : import_react41.default.createElement(import_react40.Fragment);
4712
+ }) : import_react44.default.createElement(import_react43.Fragment);
4679
4713
  }
4680
4714
  return executeAction(props);
4681
4715
  },
@@ -4690,16 +4724,16 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
4690
4724
  }
4691
4725
 
4692
4726
  // src/hooks/use-langgraph-interrupt.ts
4693
- var import_react42 = require("react");
4727
+ var import_react45 = require("react");
4694
4728
  var import_shared23 = require("@copilotkit/shared");
4695
4729
  function useLangGraphInterrupt(action, dependencies) {
4696
- const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react42.useContext)(CopilotContext);
4730
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react45.useContext)(CopilotContext);
4697
4731
  const { addToast } = useToast();
4698
- const actionId = (0, import_shared23.dataToUUID)(JSON.stringify(action), "lgAction");
4699
- (0, import_react42.useEffect)(() => {
4732
+ const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
4733
+ (0, import_react45.useEffect)(() => {
4700
4734
  if (!action)
4701
4735
  return;
4702
- setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
4736
+ setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
4703
4737
  return () => {
4704
4738
  removeInterruptAction(actionId);
4705
4739
  };
@@ -4707,10 +4741,10 @@ function useLangGraphInterrupt(action, dependencies) {
4707
4741
  }
4708
4742
 
4709
4743
  // src/hooks/use-copilot-additional-instructions.ts
4710
- var import_react43 = require("react");
4744
+ var import_react46 = require("react");
4711
4745
  function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
4712
4746
  const { setAdditionalInstructions } = useCopilotContext();
4713
- (0, import_react43.useEffect)(() => {
4747
+ (0, import_react46.useEffect)(() => {
4714
4748
  if (available === "disabled")
4715
4749
  return;
4716
4750
  setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);