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