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