@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
@@ -1,21 +1,22 @@
1
1
  import {
2
2
  useCopilotChatHeadless_c
3
- } from "../chunk-3R423LZT.mjs";
3
+ } from "../chunk-XFXT2VNX.mjs";
4
4
  import {
5
5
  defaultSystemMessage
6
- } from "../chunk-UJBV5GAG.mjs";
6
+ } from "../chunk-M7EVKKUZ.mjs";
7
+ import "../chunk-VV56AVPB.mjs";
7
8
  import "../chunk-ZVF5Q6IH.mjs";
8
- import "../chunk-R4MR43UQ.mjs";
9
- import "../chunk-CB7CRBDG.mjs";
10
9
  import "../chunk-6PUNP7CD.mjs";
11
10
  import "../chunk-O7ARI5CV.mjs";
12
- import "../chunk-NROJOTQP.mjs";
11
+ import "../chunk-QNUAXSDP.mjs";
12
+ import "../chunk-I76HKHPJ.mjs";
13
+ import "../chunk-FBVI3LQ6.mjs";
13
14
  import "../chunk-NB2FKV2V.mjs";
14
- import "../chunk-F555TVE4.mjs";
15
- import "../chunk-EFL5OBKN.mjs";
16
15
  import "../chunk-FDOMAPJY.mjs";
17
- import "../chunk-WVLHXIFP.mjs";
16
+ import "../chunk-AFNWX62Q.mjs";
18
17
  import "../chunk-DMLQZG75.mjs";
18
+ import "../chunk-F555TVE4.mjs";
19
+ import "../chunk-EFL5OBKN.mjs";
19
20
  import "../chunk-SKC7AJIV.mjs";
20
21
  export {
21
22
  defaultSystemMessage,
@@ -84,7 +84,7 @@ __export(use_copilot_chat_exports, {
84
84
  module.exports = __toCommonJS(use_copilot_chat_exports);
85
85
 
86
86
  // src/hooks/use-copilot-chat_internal.ts
87
- var import_react12 = require("react");
87
+ var import_react15 = require("react");
88
88
 
89
89
  // src/context/copilot-context.tsx
90
90
  var import_react = __toESM(require("react"));
@@ -162,7 +162,7 @@ var emptyCopilotContext = {
162
162
  interruptEventQueue: {},
163
163
  addInterruptEvent: () => {
164
164
  },
165
- removeInterruptEvent: () => {
165
+ resolveInterruptEvent: () => {
166
166
  },
167
167
  onError: () => {
168
168
  },
@@ -333,24 +333,60 @@ function useCoAgentStateRenders() {
333
333
  }
334
334
 
335
335
  // src/hooks/use-langgraph-interrupt-render.ts
336
- var import_react5 = __toESM(require("react"));
336
+ var import_react7 = __toESM(require("react"));
337
337
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
338
338
  var import_shared2 = require("@copilotkit/shared");
339
+
340
+ // src/hooks/use-agent-nodename.ts
341
+ var import_react5 = require("react");
342
+ var import_react6 = require("@copilotkitnext/react");
343
+ function useAgentNodeName(agentName) {
344
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
345
+ const nodeNameRef = (0, import_react5.useRef)("start");
346
+ (0, import_react5.useEffect)(() => {
347
+ if (!agent)
348
+ return;
349
+ const subscriber = {
350
+ onStepStartedEvent: ({ event }) => {
351
+ nodeNameRef.current = event.stepName;
352
+ },
353
+ onRunStartedEvent: () => {
354
+ nodeNameRef.current = "start";
355
+ },
356
+ onRunFinishedEvent: () => {
357
+ nodeNameRef.current = "end";
358
+ }
359
+ };
360
+ const subscription = agent.subscribe(subscriber);
361
+ return () => {
362
+ subscription.unsubscribe();
363
+ };
364
+ }, [agent]);
365
+ return nodeNameRef.current;
366
+ }
367
+
368
+ // src/hooks/use-langgraph-interrupt-render.ts
369
+ var import_react8 = require("@copilotkitnext/react");
339
370
  var InterruptRenderer = ({ event, result, render, resolve }) => {
340
371
  return render({ event, result, resolve });
341
372
  };
342
373
  function useLangGraphInterruptRender(agent) {
374
+ var _a;
343
375
  const {
344
376
  interruptActions,
345
377
  agentSession,
346
378
  threadId,
347
379
  interruptEventQueue,
348
380
  addInterruptEvent,
349
- removeInterruptEvent
381
+ resolveInterruptEvent
350
382
  } = useCopilotContext();
351
- (0, import_react5.useEffect)(() => {
383
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
384
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
385
+ const nodeName = useAgentNodeName(resolvedAgentId);
386
+ (0, import_react7.useEffect)(() => {
352
387
  if (!agent)
353
388
  return;
389
+ let localInterrupt = null;
354
390
  const subscriber = {
355
391
  onCustomEvent: ({ event }) => {
356
392
  if (event.name === "on_interrupt") {
@@ -359,12 +395,21 @@ function useLangGraphInterruptRender(agent) {
359
395
  type: event.type,
360
396
  value: (0, import_shared2.parseJson)(event.value, event.value)
361
397
  };
362
- const eventId = (0, import_shared2.dataToUUID)(JSON.stringify(eventData), "interruptEvents");
363
- addInterruptEvent({
398
+ const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
399
+ localInterrupt = {
364
400
  eventId,
365
401
  threadId,
366
402
  event: eventData
367
- });
403
+ };
404
+ }
405
+ },
406
+ onRunStartedEvent: () => {
407
+ localInterrupt = null;
408
+ },
409
+ onRunFinalized: () => {
410
+ if (localInterrupt) {
411
+ addInterruptEvent(localInterrupt);
412
+ localInterrupt = null;
368
413
  }
369
414
  }
370
415
  };
@@ -373,7 +418,7 @@ function useLangGraphInterruptRender(agent) {
373
418
  unsubscribe();
374
419
  };
375
420
  }, [agent, threadId]);
376
- const handleResolve = (0, import_react5.useCallback)(
421
+ const handleResolve = (0, import_react7.useCallback)(
377
422
  (eventId, response) => {
378
423
  agent == null ? void 0 : agent.runAgent({
379
424
  forwardedProps: {
@@ -382,15 +427,15 @@ function useLangGraphInterruptRender(agent) {
382
427
  }
383
428
  }
384
429
  });
385
- removeInterruptEvent(threadId, eventId);
430
+ resolveInterruptEvent(threadId, eventId, response != null ? response : "");
386
431
  },
387
432
  // eslint-disable-next-line react-hooks/exhaustive-deps
388
433
  [agent, threadId]
389
434
  );
390
- return (0, import_react5.useMemo)(() => {
435
+ return (0, import_react7.useMemo)(() => {
391
436
  const eventQueue = interruptEventQueue[threadId] || [];
392
437
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
393
- if (!currentQueuedEvent)
438
+ if (!currentQueuedEvent || !agentSession)
394
439
  return null;
395
440
  const allActions = Object.values(interruptActions);
396
441
  const matchingAction = allActions.find((action) => {
@@ -398,7 +443,9 @@ function useLangGraphInterruptRender(agent) {
398
443
  return true;
399
444
  return action.enabled({
400
445
  eventValue: currentQueuedEvent.event.value,
401
- agentMetadata: agentSession
446
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
447
+ nodeName
448
+ })
402
449
  });
403
450
  });
404
451
  if (!matchingAction)
@@ -416,7 +463,7 @@ function useLangGraphInterruptRender(agent) {
416
463
  }
417
464
  if (!render)
418
465
  return null;
419
- return import_react5.default.createElement(InterruptRenderer, {
466
+ return import_react7.default.createElement(InterruptRenderer, {
420
467
  event: currentQueuedEvent.event,
421
468
  result,
422
469
  render,
@@ -426,14 +473,14 @@ function useLangGraphInterruptRender(agent) {
426
473
  }
427
474
 
428
475
  // src/hooks/use-copilot-chat_internal.ts
429
- var import_react13 = require("@copilotkitnext/react");
476
+ var import_react16 = require("@copilotkitnext/react");
430
477
 
431
478
  // src/hooks/use-lazy-tool-renderer.tsx
432
- var import_react6 = require("@copilotkitnext/react");
433
- var import_react7 = require("react");
479
+ var import_react9 = require("@copilotkitnext/react");
480
+ var import_react10 = require("react");
434
481
  function useLazyToolRenderer() {
435
- const renderToolCall = (0, import_react6.useRenderToolCall)();
436
- return (0, import_react7.useCallback)(
482
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
483
+ return (0, import_react10.useCallback)(
437
484
  (message, messages) => {
438
485
  var _a;
439
486
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -454,34 +501,36 @@ function useLazyToolRenderer() {
454
501
  }
455
502
 
456
503
  // src/hooks/use-configure-chat-suggestions.tsx
457
- var import_react8 = require("@copilotkitnext/react");
458
- var import_react9 = require("react");
504
+ var import_react11 = require("@copilotkitnext/react");
505
+ var import_react12 = require("react");
459
506
  function useConfigureChatSuggestions(config, dependencies = []) {
460
- const { agentSession } = useCopilotContext();
461
- const { copilotkit } = (0, import_react8.useCopilotKit)();
507
+ var _a;
508
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
509
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
510
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
462
511
  const available = config.available === "enabled" ? "always" : config.available;
463
512
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
464
513
  available,
465
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
514
+ consumerAgentId: resolvedAgentId
466
515
  // Use chatConfig.agentId here
467
516
  });
468
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
469
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
470
- (0, import_react9.useEffect)(() => {
517
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
518
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
519
+ (0, import_react12.useEffect)(() => {
471
520
  if (finalSuggestionConfig.available === "disabled")
472
521
  return;
473
522
  const subscription = copilotkit.subscribe({
474
523
  onAgentsChanged: () => {
475
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
524
+ const agent = copilotkit.getAgent(resolvedAgentId);
476
525
  if (agent && !agent.isRunning && !result.suggestions.length) {
477
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
526
+ copilotkit.reloadSuggestions(resolvedAgentId);
478
527
  }
479
528
  }
480
529
  });
481
530
  return () => {
482
531
  subscription.unsubscribe();
483
532
  };
484
- }, []);
533
+ }, [resolvedAgentId]);
485
534
  return result;
486
535
  }
487
536
 
@@ -891,10 +940,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
891
940
  ]);
892
941
 
893
942
  // src/hooks/use-coagent-state-render-bridge.tsx
894
- var import_react10 = require("@copilotkitnext/react");
895
- var import_react11 = require("react");
943
+ var import_react13 = require("@copilotkitnext/react");
944
+ var import_react14 = require("react");
896
945
  var import_shared3 = require("@copilotkit/shared");
897
946
  function getStateWithoutConstantKeys(state) {
947
+ if (!state)
948
+ return {};
898
949
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
899
950
  return stateWithoutConstantKeys;
900
951
  }
@@ -917,11 +968,11 @@ function useCoagentStateRenderBridge(agentId, props) {
917
968
  var _a;
918
969
  const { stateSnapshot, messageIndexInRun, message } = props;
919
970
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
920
- const { agent } = (0, import_react10.useAgent)({ agentId });
921
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
971
+ const { agent } = (0, import_react13.useAgent)({ agentId });
972
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
922
973
  const runId = (_a = props.runId) != null ? _a : message.runId;
923
974
  const effectiveRunId = runId || "pending";
924
- (0, import_react11.useEffect)(() => {
975
+ (0, import_react14.useEffect)(() => {
925
976
  if (!agent)
926
977
  return;
927
978
  const subscriber = {
@@ -941,10 +992,7 @@ function useCoagentStateRenderBridge(agentId, props) {
941
992
  unsubscribe();
942
993
  };
943
994
  }, [agentId, nodeName]);
944
- if (messageIndexInRun !== 0) {
945
- return null;
946
- }
947
- const getStateRender = (0, import_react11.useCallback)(
995
+ const getStateRender = (0, import_react14.useCallback)(
948
996
  (messageId) => {
949
997
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
950
998
  if (claimsRef.current[messageId]) {
@@ -971,7 +1019,7 @@ function useCoagentStateRenderBridge(agentId, props) {
971
1019
  return canRender;
972
1020
  }
973
1021
  const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
974
- (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
1022
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
975
1023
  );
976
1024
  if (renderClaimedByOtherMessage) {
977
1025
  if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
@@ -986,8 +1034,11 @@ function useCoagentStateRenderBridge(agentId, props) {
986
1034
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
987
1035
  return true;
988
1036
  };
989
- return (0, import_react11.useMemo)(() => {
1037
+ return (0, import_react14.useMemo)(() => {
990
1038
  var _a2, _b, _c;
1039
+ if (messageIndexInRun !== 0) {
1040
+ return null;
1041
+ }
991
1042
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
992
1043
  if (!stateRender || !stateRenderId) {
993
1044
  return null;
@@ -1034,7 +1085,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1034
1085
  agent == null ? void 0 : agent.isRunning,
1035
1086
  nodeName,
1036
1087
  effectiveRunId,
1037
- message.id
1088
+ message.id,
1089
+ messageIndexInRun
1038
1090
  ]);
1039
1091
  }
1040
1092
  function CoAgentStateRenderBridge(props) {
@@ -1062,15 +1114,15 @@ function useConfigureSuggestions2(suggestions) {
1062
1114
  function useCopilotChatInternal({
1063
1115
  suggestions
1064
1116
  } = {}) {
1065
- var _a, _b, _c, _d;
1066
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1117
+ var _a, _b, _c;
1118
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1067
1119
  const { threadId, agentSession } = useCopilotContext();
1068
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1069
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1120
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1121
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1070
1122
  useConfigureSuggestions2(suggestions);
1071
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1072
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1073
- (0, import_react12.useEffect)(() => {
1123
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1124
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1125
+ (0, import_react15.useEffect)(() => {
1074
1126
  const connect = (agent2) => __async(this, null, function* () {
1075
1127
  setAgentAvailable(false);
1076
1128
  try {
@@ -1095,7 +1147,7 @@ function useCopilotChatInternal({
1095
1147
  agent == null ? void 0 : agent.setMessages([]);
1096
1148
  agent == null ? void 0 : agent.setState(null);
1097
1149
  };
1098
- const deleteMessage = (0, import_react12.useCallback)(
1150
+ const deleteMessage = (0, import_react15.useCallback)(
1099
1151
  (messageId) => {
1100
1152
  var _a2;
1101
1153
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1106,13 +1158,13 @@ function useCopilotChatInternal({
1106
1158
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1107
1159
  );
1108
1160
  const latestDelete = useUpdatedRef(deleteMessage);
1109
- const latestDeleteFunc = (0, import_react12.useCallback)(
1161
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1110
1162
  (messageId) => {
1111
1163
  return latestDelete.current(messageId);
1112
1164
  },
1113
1165
  [latestDelete]
1114
1166
  );
1115
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1167
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1116
1168
  const reload = useAsyncCallback(
1117
1169
  (reloadMessageId) => __async(this, null, function* () {
1118
1170
  var _a2;
@@ -1180,7 +1232,7 @@ function useCopilotChatInternal({
1180
1232
  [latestSendMessageFunc]
1181
1233
  );
1182
1234
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1183
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1235
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1184
1236
  (messages) => {
1185
1237
  var _a2, _b2;
1186
1238
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1198,24 +1250,24 @@ function useCopilotChatInternal({
1198
1250
  [latestReload]
1199
1251
  );
1200
1252
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1201
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1253
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1202
1254
  var _a2;
1203
1255
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1204
1256
  }, [latestStop]);
1205
1257
  const latestReset = useUpdatedRef(reset);
1206
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1258
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1207
1259
  return latestReset.current();
1208
1260
  }, [latestReset]);
1209
1261
  const lazyToolRendered = useLazyToolRenderer();
1210
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1262
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1211
1263
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1212
1264
  copilotkit,
1213
1265
  agent,
1214
1266
  agentId: resolvedAgentId,
1215
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1267
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1216
1268
  });
1217
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1218
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1269
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1270
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1219
1271
  let processedMessages = allMessages.map((message) => {
1220
1272
  if (message.role !== "assistant") {
1221
1273
  return message;
@@ -1243,31 +1295,13 @@ function useCopilotChatInternal({
1243
1295
  return message;
1244
1296
  });
1245
1297
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1246
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1247
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1248
- const placeholderMessage = {
1249
- id: placeholderId,
1250
- role: "assistant",
1251
- content: "",
1252
- name: "coagent-state-render"
1253
- };
1254
- processedMessages = [
1255
- ...processedMessages,
1256
- __spreadProps(__spreadValues({}, placeholderMessage), {
1257
- generativeUI: () => legacyCustomMessageRenderer({
1258
- message: placeholderMessage,
1259
- position: "before"
1260
- })
1261
- })
1262
- ];
1263
- }
1264
1298
  return processedMessages;
1265
1299
  }, [
1266
1300
  agent == null ? void 0 : agent.messages,
1267
1301
  lazyToolRendered,
1268
1302
  allMessages,
1269
1303
  renderCustomMessage,
1270
- legacyCustomMessageRenderer,
1304
+ // legacyCustomMessageRenderer,
1271
1305
  resolvedAgentId
1272
1306
  ]);
1273
1307
  return {
@@ -1279,7 +1313,7 @@ function useCopilotChatInternal({
1279
1313
  stopGeneration: latestStopFunc,
1280
1314
  reset: latestResetFunc,
1281
1315
  deleteMessage: latestDeleteFunc,
1282
- isAvailable: !agentAvailable,
1316
+ isAvailable: agentAvailable,
1283
1317
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1284
1318
  // mcpServers,
1285
1319
  // setMcpServers,
@@ -1296,8 +1330,8 @@ function useCopilotChatInternal({
1296
1330
  };
1297
1331
  }
1298
1332
  function useUpdatedRef(value) {
1299
- const ref = (0, import_react12.useRef)(value);
1300
- (0, import_react12.useEffect)(() => {
1333
+ const ref = (0, import_react15.useRef)(value);
1334
+ (0, import_react15.useEffect)(() => {
1301
1335
  ref.current = value;
1302
1336
  }, [value]);
1303
1337
  return ref;
@@ -1308,20 +1342,19 @@ function useLegacyCoagentRenderer({
1308
1342
  agentId,
1309
1343
  threadId
1310
1344
  }) {
1311
- return (0, import_react12.useMemo)(() => {
1345
+ return (0, import_react15.useMemo)(() => {
1312
1346
  if (!copilotkit || !agent) {
1313
1347
  return null;
1314
1348
  }
1315
1349
  return ({ message, position }) => {
1316
1350
  var _a;
1317
1351
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1318
- const existingRunId = copilotkit.getRunIdForMessage(
1319
- agentId,
1320
- effectiveThreadId,
1321
- message.id
1322
- );
1352
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1323
1353
  const runId = existingRunId || `pending:${message.id}`;
1324
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1354
+ const messageIndex = Math.max(
1355
+ agent.messages.findIndex((msg) => msg.id === message.id),
1356
+ 0
1357
+ );
1325
1358
  const bridgeProps = {
1326
1359
  message,
1327
1360
  position,
@@ -1332,7 +1365,7 @@ function useLegacyCoagentRenderer({
1332
1365
  agentId,
1333
1366
  stateSnapshot: message.state
1334
1367
  };
1335
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1368
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1336
1369
  };
1337
1370
  }, [agent, agentId, copilotkit, threadId]);
1338
1371
  }