@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
@@ -102,7 +102,7 @@ __export(hooks_exports, {
102
102
  module.exports = __toCommonJS(hooks_exports);
103
103
 
104
104
  // src/hooks/use-copilot-chat_internal.ts
105
- var import_react12 = require("react");
105
+ var import_react15 = require("react");
106
106
 
107
107
  // src/context/copilot-context.tsx
108
108
  var import_react = __toESM(require("react"));
@@ -180,7 +180,7 @@ var emptyCopilotContext = {
180
180
  interruptEventQueue: {},
181
181
  addInterruptEvent: () => {
182
182
  },
183
- removeInterruptEvent: () => {
183
+ resolveInterruptEvent: () => {
184
184
  },
185
185
  onError: () => {
186
186
  },
@@ -351,24 +351,60 @@ function useCoAgentStateRenders() {
351
351
  }
352
352
 
353
353
  // src/hooks/use-langgraph-interrupt-render.ts
354
- var import_react5 = __toESM(require("react"));
354
+ var import_react7 = __toESM(require("react"));
355
355
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
356
356
  var import_shared2 = require("@copilotkit/shared");
357
+
358
+ // src/hooks/use-agent-nodename.ts
359
+ var import_react5 = require("react");
360
+ var import_react6 = require("@copilotkitnext/react");
361
+ function useAgentNodeName(agentName) {
362
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
363
+ const nodeNameRef = (0, import_react5.useRef)("start");
364
+ (0, import_react5.useEffect)(() => {
365
+ if (!agent)
366
+ return;
367
+ const subscriber = {
368
+ onStepStartedEvent: ({ event }) => {
369
+ nodeNameRef.current = event.stepName;
370
+ },
371
+ onRunStartedEvent: () => {
372
+ nodeNameRef.current = "start";
373
+ },
374
+ onRunFinishedEvent: () => {
375
+ nodeNameRef.current = "end";
376
+ }
377
+ };
378
+ const subscription = agent.subscribe(subscriber);
379
+ return () => {
380
+ subscription.unsubscribe();
381
+ };
382
+ }, [agent]);
383
+ return nodeNameRef.current;
384
+ }
385
+
386
+ // src/hooks/use-langgraph-interrupt-render.ts
387
+ var import_react8 = require("@copilotkitnext/react");
357
388
  var InterruptRenderer = ({ event, result, render, resolve }) => {
358
389
  return render({ event, result, resolve });
359
390
  };
360
391
  function useLangGraphInterruptRender(agent) {
392
+ var _a;
361
393
  const {
362
394
  interruptActions,
363
395
  agentSession,
364
396
  threadId,
365
397
  interruptEventQueue,
366
398
  addInterruptEvent,
367
- removeInterruptEvent
399
+ resolveInterruptEvent
368
400
  } = useCopilotContext();
369
- (0, import_react5.useEffect)(() => {
401
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
402
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
403
+ const nodeName = useAgentNodeName(resolvedAgentId);
404
+ (0, import_react7.useEffect)(() => {
370
405
  if (!agent)
371
406
  return;
407
+ let localInterrupt = null;
372
408
  const subscriber = {
373
409
  onCustomEvent: ({ event }) => {
374
410
  if (event.name === "on_interrupt") {
@@ -377,12 +413,21 @@ function useLangGraphInterruptRender(agent) {
377
413
  type: event.type,
378
414
  value: (0, import_shared2.parseJson)(event.value, event.value)
379
415
  };
380
- const eventId = (0, import_shared2.dataToUUID)(JSON.stringify(eventData), "interruptEvents");
381
- addInterruptEvent({
416
+ const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
417
+ localInterrupt = {
382
418
  eventId,
383
419
  threadId,
384
420
  event: eventData
385
- });
421
+ };
422
+ }
423
+ },
424
+ onRunStartedEvent: () => {
425
+ localInterrupt = null;
426
+ },
427
+ onRunFinalized: () => {
428
+ if (localInterrupt) {
429
+ addInterruptEvent(localInterrupt);
430
+ localInterrupt = null;
386
431
  }
387
432
  }
388
433
  };
@@ -391,7 +436,7 @@ function useLangGraphInterruptRender(agent) {
391
436
  unsubscribe();
392
437
  };
393
438
  }, [agent, threadId]);
394
- const handleResolve = (0, import_react5.useCallback)(
439
+ const handleResolve = (0, import_react7.useCallback)(
395
440
  (eventId, response) => {
396
441
  agent == null ? void 0 : agent.runAgent({
397
442
  forwardedProps: {
@@ -400,15 +445,15 @@ function useLangGraphInterruptRender(agent) {
400
445
  }
401
446
  }
402
447
  });
403
- removeInterruptEvent(threadId, eventId);
448
+ resolveInterruptEvent(threadId, eventId, response != null ? response : "");
404
449
  },
405
450
  // eslint-disable-next-line react-hooks/exhaustive-deps
406
451
  [agent, threadId]
407
452
  );
408
- return (0, import_react5.useMemo)(() => {
453
+ return (0, import_react7.useMemo)(() => {
409
454
  const eventQueue = interruptEventQueue[threadId] || [];
410
455
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
411
- if (!currentQueuedEvent)
456
+ if (!currentQueuedEvent || !agentSession)
412
457
  return null;
413
458
  const allActions = Object.values(interruptActions);
414
459
  const matchingAction = allActions.find((action) => {
@@ -416,7 +461,9 @@ function useLangGraphInterruptRender(agent) {
416
461
  return true;
417
462
  return action.enabled({
418
463
  eventValue: currentQueuedEvent.event.value,
419
- agentMetadata: agentSession
464
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
465
+ nodeName
466
+ })
420
467
  });
421
468
  });
422
469
  if (!matchingAction)
@@ -434,7 +481,7 @@ function useLangGraphInterruptRender(agent) {
434
481
  }
435
482
  if (!render)
436
483
  return null;
437
- return import_react5.default.createElement(InterruptRenderer, {
484
+ return import_react7.default.createElement(InterruptRenderer, {
438
485
  event: currentQueuedEvent.event,
439
486
  result,
440
487
  render,
@@ -444,14 +491,14 @@ function useLangGraphInterruptRender(agent) {
444
491
  }
445
492
 
446
493
  // src/hooks/use-copilot-chat_internal.ts
447
- var import_react13 = require("@copilotkitnext/react");
494
+ var import_react16 = require("@copilotkitnext/react");
448
495
 
449
496
  // src/hooks/use-lazy-tool-renderer.tsx
450
- var import_react6 = require("@copilotkitnext/react");
451
- var import_react7 = require("react");
497
+ var import_react9 = require("@copilotkitnext/react");
498
+ var import_react10 = require("react");
452
499
  function useLazyToolRenderer() {
453
- const renderToolCall = (0, import_react6.useRenderToolCall)();
454
- return (0, import_react7.useCallback)(
500
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
501
+ return (0, import_react10.useCallback)(
455
502
  (message, messages) => {
456
503
  var _a;
457
504
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -472,34 +519,36 @@ function useLazyToolRenderer() {
472
519
  }
473
520
 
474
521
  // src/hooks/use-configure-chat-suggestions.tsx
475
- var import_react8 = require("@copilotkitnext/react");
476
- var import_react9 = require("react");
522
+ var import_react11 = require("@copilotkitnext/react");
523
+ var import_react12 = require("react");
477
524
  function useConfigureChatSuggestions(config, dependencies = []) {
478
- const { agentSession } = useCopilotContext();
479
- const { copilotkit } = (0, import_react8.useCopilotKit)();
525
+ var _a;
526
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
527
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
528
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
480
529
  const available = config.available === "enabled" ? "always" : config.available;
481
530
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
482
531
  available,
483
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
532
+ consumerAgentId: resolvedAgentId
484
533
  // Use chatConfig.agentId here
485
534
  });
486
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
487
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
488
- (0, import_react9.useEffect)(() => {
535
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
536
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
537
+ (0, import_react12.useEffect)(() => {
489
538
  if (finalSuggestionConfig.available === "disabled")
490
539
  return;
491
540
  const subscription = copilotkit.subscribe({
492
541
  onAgentsChanged: () => {
493
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
542
+ const agent = copilotkit.getAgent(resolvedAgentId);
494
543
  if (agent && !agent.isRunning && !result.suggestions.length) {
495
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
544
+ copilotkit.reloadSuggestions(resolvedAgentId);
496
545
  }
497
546
  }
498
547
  });
499
548
  return () => {
500
549
  subscription.unsubscribe();
501
550
  };
502
- }, []);
551
+ }, [resolvedAgentId]);
503
552
  return result;
504
553
  }
505
554
 
@@ -909,10 +958,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
909
958
  ]);
910
959
 
911
960
  // src/hooks/use-coagent-state-render-bridge.tsx
912
- var import_react10 = require("@copilotkitnext/react");
913
- var import_react11 = require("react");
961
+ var import_react13 = require("@copilotkitnext/react");
962
+ var import_react14 = require("react");
914
963
  var import_shared3 = require("@copilotkit/shared");
915
964
  function getStateWithoutConstantKeys(state) {
965
+ if (!state)
966
+ return {};
916
967
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
917
968
  return stateWithoutConstantKeys;
918
969
  }
@@ -935,11 +986,11 @@ function useCoagentStateRenderBridge(agentId, props) {
935
986
  var _a;
936
987
  const { stateSnapshot, messageIndexInRun, message } = props;
937
988
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
938
- const { agent } = (0, import_react10.useAgent)({ agentId });
939
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
989
+ const { agent } = (0, import_react13.useAgent)({ agentId });
990
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
940
991
  const runId = (_a = props.runId) != null ? _a : message.runId;
941
992
  const effectiveRunId = runId || "pending";
942
- (0, import_react11.useEffect)(() => {
993
+ (0, import_react14.useEffect)(() => {
943
994
  if (!agent)
944
995
  return;
945
996
  const subscriber = {
@@ -959,10 +1010,7 @@ function useCoagentStateRenderBridge(agentId, props) {
959
1010
  unsubscribe();
960
1011
  };
961
1012
  }, [agentId, nodeName]);
962
- if (messageIndexInRun !== 0) {
963
- return null;
964
- }
965
- const getStateRender = (0, import_react11.useCallback)(
1013
+ const getStateRender = (0, import_react14.useCallback)(
966
1014
  (messageId) => {
967
1015
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
968
1016
  if (claimsRef.current[messageId]) {
@@ -989,7 +1037,7 @@ function useCoagentStateRenderBridge(agentId, props) {
989
1037
  return canRender;
990
1038
  }
991
1039
  const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
992
- (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
1040
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
993
1041
  );
994
1042
  if (renderClaimedByOtherMessage) {
995
1043
  if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
@@ -1004,8 +1052,11 @@ function useCoagentStateRenderBridge(agentId, props) {
1004
1052
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1005
1053
  return true;
1006
1054
  };
1007
- return (0, import_react11.useMemo)(() => {
1055
+ return (0, import_react14.useMemo)(() => {
1008
1056
  var _a2, _b, _c;
1057
+ if (messageIndexInRun !== 0) {
1058
+ return null;
1059
+ }
1009
1060
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
1010
1061
  if (!stateRender || !stateRenderId) {
1011
1062
  return null;
@@ -1052,7 +1103,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1052
1103
  agent == null ? void 0 : agent.isRunning,
1053
1104
  nodeName,
1054
1105
  effectiveRunId,
1055
- message.id
1106
+ message.id,
1107
+ messageIndexInRun
1056
1108
  ]);
1057
1109
  }
1058
1110
  function CoAgentStateRenderBridge(props) {
@@ -1080,15 +1132,15 @@ function useConfigureSuggestions2(suggestions) {
1080
1132
  function useCopilotChatInternal({
1081
1133
  suggestions
1082
1134
  } = {}) {
1083
- var _a, _b, _c, _d;
1084
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1135
+ var _a, _b, _c;
1136
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1085
1137
  const { threadId, agentSession } = useCopilotContext();
1086
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1087
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1138
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1139
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1088
1140
  useConfigureSuggestions2(suggestions);
1089
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1090
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1091
- (0, import_react12.useEffect)(() => {
1141
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1142
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1143
+ (0, import_react15.useEffect)(() => {
1092
1144
  const connect = (agent2) => __async(this, null, function* () {
1093
1145
  setAgentAvailable(false);
1094
1146
  try {
@@ -1113,7 +1165,7 @@ function useCopilotChatInternal({
1113
1165
  agent == null ? void 0 : agent.setMessages([]);
1114
1166
  agent == null ? void 0 : agent.setState(null);
1115
1167
  };
1116
- const deleteMessage = (0, import_react12.useCallback)(
1168
+ const deleteMessage = (0, import_react15.useCallback)(
1117
1169
  (messageId) => {
1118
1170
  var _a2;
1119
1171
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1124,13 +1176,13 @@ function useCopilotChatInternal({
1124
1176
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1125
1177
  );
1126
1178
  const latestDelete = useUpdatedRef(deleteMessage);
1127
- const latestDeleteFunc = (0, import_react12.useCallback)(
1179
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1128
1180
  (messageId) => {
1129
1181
  return latestDelete.current(messageId);
1130
1182
  },
1131
1183
  [latestDelete]
1132
1184
  );
1133
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1185
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1134
1186
  const reload = useAsyncCallback(
1135
1187
  (reloadMessageId) => __async(this, null, function* () {
1136
1188
  var _a2;
@@ -1198,7 +1250,7 @@ function useCopilotChatInternal({
1198
1250
  [latestSendMessageFunc]
1199
1251
  );
1200
1252
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1201
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1253
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1202
1254
  (messages) => {
1203
1255
  var _a2, _b2;
1204
1256
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1216,24 +1268,24 @@ function useCopilotChatInternal({
1216
1268
  [latestReload]
1217
1269
  );
1218
1270
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1219
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1271
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1220
1272
  var _a2;
1221
1273
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1222
1274
  }, [latestStop]);
1223
1275
  const latestReset = useUpdatedRef(reset);
1224
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1276
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1225
1277
  return latestReset.current();
1226
1278
  }, [latestReset]);
1227
1279
  const lazyToolRendered = useLazyToolRenderer();
1228
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1280
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1229
1281
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1230
1282
  copilotkit,
1231
1283
  agent,
1232
1284
  agentId: resolvedAgentId,
1233
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1285
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1234
1286
  });
1235
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1236
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1287
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1288
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1237
1289
  let processedMessages = allMessages.map((message) => {
1238
1290
  if (message.role !== "assistant") {
1239
1291
  return message;
@@ -1261,31 +1313,13 @@ function useCopilotChatInternal({
1261
1313
  return message;
1262
1314
  });
1263
1315
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1264
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1265
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1266
- const placeholderMessage = {
1267
- id: placeholderId,
1268
- role: "assistant",
1269
- content: "",
1270
- name: "coagent-state-render"
1271
- };
1272
- processedMessages = [
1273
- ...processedMessages,
1274
- __spreadProps(__spreadValues({}, placeholderMessage), {
1275
- generativeUI: () => legacyCustomMessageRenderer({
1276
- message: placeholderMessage,
1277
- position: "before"
1278
- })
1279
- })
1280
- ];
1281
- }
1282
1316
  return processedMessages;
1283
1317
  }, [
1284
1318
  agent == null ? void 0 : agent.messages,
1285
1319
  lazyToolRendered,
1286
1320
  allMessages,
1287
1321
  renderCustomMessage,
1288
- legacyCustomMessageRenderer,
1322
+ // legacyCustomMessageRenderer,
1289
1323
  resolvedAgentId
1290
1324
  ]);
1291
1325
  return {
@@ -1297,7 +1331,7 @@ function useCopilotChatInternal({
1297
1331
  stopGeneration: latestStopFunc,
1298
1332
  reset: latestResetFunc,
1299
1333
  deleteMessage: latestDeleteFunc,
1300
- isAvailable: !agentAvailable,
1334
+ isAvailable: agentAvailable,
1301
1335
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1302
1336
  // mcpServers,
1303
1337
  // setMcpServers,
@@ -1314,8 +1348,8 @@ function useCopilotChatInternal({
1314
1348
  };
1315
1349
  }
1316
1350
  function useUpdatedRef(value) {
1317
- const ref = (0, import_react12.useRef)(value);
1318
- (0, import_react12.useEffect)(() => {
1351
+ const ref = (0, import_react15.useRef)(value);
1352
+ (0, import_react15.useEffect)(() => {
1319
1353
  ref.current = value;
1320
1354
  }, [value]);
1321
1355
  return ref;
@@ -1326,20 +1360,19 @@ function useLegacyCoagentRenderer({
1326
1360
  agentId,
1327
1361
  threadId
1328
1362
  }) {
1329
- return (0, import_react12.useMemo)(() => {
1363
+ return (0, import_react15.useMemo)(() => {
1330
1364
  if (!copilotkit || !agent) {
1331
1365
  return null;
1332
1366
  }
1333
1367
  return ({ message, position }) => {
1334
1368
  var _a;
1335
1369
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1336
- const existingRunId = copilotkit.getRunIdForMessage(
1337
- agentId,
1338
- effectiveThreadId,
1339
- message.id
1340
- );
1370
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1341
1371
  const runId = existingRunId || `pending:${message.id}`;
1342
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1372
+ const messageIndex = Math.max(
1373
+ agent.messages.findIndex((msg) => msg.id === message.id),
1374
+ 0
1375
+ );
1343
1376
  const bridgeProps = {
1344
1377
  message,
1345
1378
  position,
@@ -1350,7 +1383,7 @@ function useLegacyCoagentRenderer({
1350
1383
  agentId,
1351
1384
  stateSnapshot: message.state
1352
1385
  };
1353
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1386
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1354
1387
  };
1355
1388
  }, [agent, agentId, copilotkit, threadId]);
1356
1389
  }
@@ -1384,7 +1417,7 @@ function useCopilotChat(options = {}) {
1384
1417
  }
1385
1418
 
1386
1419
  // src/hooks/use-copilot-chat-headless_c.ts
1387
- var import_react14 = require("react");
1420
+ var import_react17 = require("react");
1388
1421
  var import_shared4 = require("@copilotkit/shared");
1389
1422
  var createNonFunctionalReturn = () => ({
1390
1423
  visibleMessages: [],
@@ -1425,7 +1458,7 @@ function useCopilotChatHeadless_c(options = {}) {
1425
1458
  const { copilotApiConfig, setBannerError } = useCopilotContext();
1426
1459
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
1427
1460
  const internalResult = useCopilotChatInternal(options);
1428
- (0, import_react14.useEffect)(() => {
1461
+ (0, import_react17.useEffect)(() => {
1429
1462
  if (!hasPublicApiKey) {
1430
1463
  setBannerError(
1431
1464
  new import_shared4.CopilotKitError({
@@ -1450,13 +1483,13 @@ function useCopilotChatHeadless_c(options = {}) {
1450
1483
  }
1451
1484
 
1452
1485
  // src/hooks/use-copilot-action.ts
1453
- var import_react21 = require("react");
1486
+ var import_react24 = require("react");
1454
1487
 
1455
1488
  // src/hooks/use-frontend-tool.ts
1456
- var import_react15 = __toESM(require("react"));
1489
+ var import_react18 = __toESM(require("react"));
1457
1490
  var import_shared5 = require("@copilotkit/shared");
1458
1491
  var import_shared6 = require("@copilotkit/shared");
1459
- var import_react16 = require("@copilotkitnext/react");
1492
+ var import_react19 = require("@copilotkitnext/react");
1460
1493
  function useFrontendTool(tool, dependencies) {
1461
1494
  const { name, description, parameters, render, followUp } = tool;
1462
1495
  const zodParameters = (0, import_shared5.getZodParameters)(parameters);
@@ -1466,7 +1499,11 @@ function useFrontendTool(tool, dependencies) {
1466
1499
  }
1467
1500
  if (typeof render === "string") {
1468
1501
  const staticRender = render;
1469
- return () => import_react15.default.createElement(import_react15.default.Fragment, null, staticRender);
1502
+ return () => import_react18.default.createElement(
1503
+ import_react18.default.Fragment,
1504
+ null,
1505
+ staticRender
1506
+ );
1470
1507
  }
1471
1508
  return (args) => {
1472
1509
  const renderArgs = __spreadProps(__spreadValues({}, args), {
@@ -1474,12 +1511,12 @@ function useFrontendTool(tool, dependencies) {
1474
1511
  });
1475
1512
  const rendered = render(renderArgs);
1476
1513
  if (typeof rendered === "string") {
1477
- return import_react15.default.createElement(import_react15.default.Fragment, null, rendered);
1514
+ return import_react18.default.createElement(import_react18.default.Fragment, null, rendered);
1478
1515
  }
1479
1516
  return rendered != null ? rendered : null;
1480
1517
  };
1481
1518
  })();
1482
- (0, import_react16.useFrontendTool)({
1519
+ (0, import_react19.useFrontendTool)({
1483
1520
  name,
1484
1521
  description,
1485
1522
  parameters: zodParameters,
@@ -1491,23 +1528,23 @@ function useFrontendTool(tool, dependencies) {
1491
1528
 
1492
1529
  // src/hooks/use-render-tool-call.ts
1493
1530
  var import_shared7 = require("@copilotkit/shared");
1494
- var import_react17 = require("react");
1495
- var import_react18 = require("@copilotkitnext/react");
1531
+ var import_react20 = require("react");
1532
+ var import_react21 = require("@copilotkitnext/react");
1496
1533
  var import_shared8 = require("@copilotkit/shared");
1497
1534
  function useRenderToolCall2(tool, dependencies) {
1498
- const { copilotkit } = (0, import_react18.useCopilotKit)();
1499
- const hasAddedRef = (0, import_react17.useRef)(false);
1500
- (0, import_react17.useEffect)(() => {
1535
+ const { copilotkit } = (0, import_react21.useCopilotKit)();
1536
+ const hasAddedRef = (0, import_react20.useRef)(false);
1537
+ (0, import_react20.useEffect)(() => {
1501
1538
  const { name, parameters, render } = tool;
1502
1539
  const zodParameters = (0, import_shared7.getZodParameters)(parameters);
1503
- const renderToolCall = name === "*" ? (0, import_react18.defineToolCallRenderer)({
1540
+ const renderToolCall = name === "*" ? (0, import_react21.defineToolCallRenderer)({
1504
1541
  name: "*",
1505
1542
  render: (args) => {
1506
1543
  return render(__spreadProps(__spreadValues({}, args), {
1507
1544
  result: args.result ? (0, import_shared8.parseJson)(args.result, args.result) : args.result
1508
1545
  }));
1509
1546
  }
1510
- }) : (0, import_react18.defineToolCallRenderer)({
1547
+ }) : (0, import_react21.defineToolCallRenderer)({
1511
1548
  name,
1512
1549
  args: zodParameters,
1513
1550
  render: (args) => {
@@ -1536,18 +1573,18 @@ function useRenderToolCall2(tool, dependencies) {
1536
1573
 
1537
1574
  // src/hooks/use-human-in-the-loop.ts
1538
1575
  var import_shared9 = require("@copilotkit/shared");
1539
- var import_react19 = require("@copilotkitnext/react");
1576
+ var import_react22 = require("@copilotkitnext/react");
1540
1577
  var import_core = require("@copilotkitnext/core");
1541
- var import_react20 = __toESM(require("react"));
1578
+ var import_react23 = __toESM(require("react"));
1542
1579
  function useHumanInTheLoop(tool, dependencies) {
1543
1580
  const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
1544
1581
  const { name, description, parameters, followUp } = toolRest;
1545
1582
  const zodParameters = (0, import_shared9.getZodParameters)(parameters);
1546
- const renderRef = (0, import_react20.useRef)(null);
1547
- (0, import_react20.useEffect)(() => {
1583
+ const renderRef = (0, import_react23.useRef)(null);
1584
+ (0, import_react23.useEffect)(() => {
1548
1585
  renderRef.current = (args) => {
1549
1586
  if (typeof render === "string") {
1550
- return import_react20.default.createElement(import_react20.default.Fragment, null, render);
1587
+ return import_react23.default.createElement(import_react23.default.Fragment, null, render);
1551
1588
  }
1552
1589
  if (!render) {
1553
1590
  return null;
@@ -1587,12 +1624,12 @@ function useHumanInTheLoop(tool, dependencies) {
1587
1624
  })();
1588
1625
  const rendered = render(renderProps);
1589
1626
  if (typeof rendered === "string") {
1590
- return import_react20.default.createElement(import_react20.default.Fragment, null, rendered);
1627
+ return import_react23.default.createElement(import_react23.default.Fragment, null, rendered);
1591
1628
  }
1592
1629
  return rendered != null ? rendered : null;
1593
1630
  };
1594
1631
  }, [render, ...dependencies != null ? dependencies : []]);
1595
- (0, import_react19.useHumanInTheLoop)({
1632
+ (0, import_react22.useHumanInTheLoop)({
1596
1633
  name,
1597
1634
  description,
1598
1635
  followUp,
@@ -1648,7 +1685,7 @@ function getActionConfig(action) {
1648
1685
  throw new Error("Invalid action configuration");
1649
1686
  }
1650
1687
  function useCopilotAction(action, dependencies) {
1651
- const [initialActionConfig] = (0, import_react21.useState)(getActionConfig(action));
1688
+ const [initialActionConfig] = (0, import_react24.useState)(getActionConfig(action));
1652
1689
  const currentActionConfig = getActionConfig(action);
1653
1690
  if (initialActionConfig.type !== currentActionConfig.type) {
1654
1691
  throw new Error("Action configuration changed between renders");
@@ -1666,14 +1703,14 @@ function useCopilotAction(action, dependencies) {
1666
1703
  }
1667
1704
 
1668
1705
  // src/hooks/use-coagent-state-render.ts
1669
- var import_react22 = require("react");
1706
+ var import_react25 = require("react");
1670
1707
  var import_shared10 = require("@copilotkit/shared");
1671
1708
  function useCoAgentStateRender(action, dependencies) {
1672
- const { chatComponentsCache, availableAgents } = (0, import_react22.useContext)(CopilotContext);
1709
+ const { chatComponentsCache, availableAgents } = (0, import_react25.useContext)(CopilotContext);
1673
1710
  const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
1674
- const idRef = (0, import_react22.useRef)((0, import_shared10.randomId)());
1711
+ const idRef = (0, import_react25.useRef)((0, import_shared10.randomId)());
1675
1712
  const { setBannerError, addToast } = useToast();
1676
- (0, import_react22.useEffect)(() => {
1713
+ (0, import_react25.useEffect)(() => {
1677
1714
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
1678
1715
  const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
1679
1716
  const agentError = new import_shared10.CopilotKitAgentDiscoveryError({
@@ -1694,7 +1731,7 @@ function useCoAgentStateRender(action, dependencies) {
1694
1731
  }
1695
1732
  }
1696
1733
  }
1697
- (0, import_react22.useEffect)(() => {
1734
+ (0, import_react25.useEffect)(() => {
1698
1735
  const currentId = idRef.current;
1699
1736
  const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
1700
1737
  if (id === currentId)
@@ -1718,7 +1755,7 @@ function useCoAgentStateRender(action, dependencies) {
1718
1755
  });
1719
1756
  }
1720
1757
  }, [coAgentStateRenders]);
1721
- (0, import_react22.useEffect)(() => {
1758
+ (0, import_react25.useEffect)(() => {
1722
1759
  setCoAgentStateRender(idRef.current, action);
1723
1760
  if (chatComponentsCache.current !== null && action.render !== void 0) {
1724
1761
  chatComponentsCache.current.coAgentStateRenders[key] = action.render;
@@ -1738,11 +1775,11 @@ function useCoAgentStateRender(action, dependencies) {
1738
1775
  }
1739
1776
 
1740
1777
  // src/hooks/use-make-copilot-document-readable.ts
1741
- var import_react23 = require("react");
1778
+ var import_react26 = require("react");
1742
1779
  function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
1743
1780
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
1744
- const idRef = (0, import_react23.useRef)(void 0);
1745
- (0, import_react23.useEffect)(() => {
1781
+ const idRef = (0, import_react26.useRef)(void 0);
1782
+ (0, import_react26.useEffect)(() => {
1746
1783
  const id = addDocumentContext(document, categories);
1747
1784
  idRef.current = id;
1748
1785
  return () => {
@@ -1753,21 +1790,23 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
1753
1790
  }
1754
1791
 
1755
1792
  // src/hooks/use-copilot-readable.ts
1756
- var import_react24 = require("@copilotkitnext/react");
1793
+ var import_react27 = require("@copilotkitnext/react");
1757
1794
  function useCopilotReadable({ description, value }, dependencies) {
1758
- (0, import_react24.useAgentContext)({
1795
+ (0, import_react27.useAgentContext)({
1759
1796
  description,
1760
1797
  value
1761
1798
  });
1799
+ return;
1762
1800
  }
1763
1801
 
1764
1802
  // src/hooks/use-coagent.ts
1765
- var import_react25 = require("react");
1766
- var import_react26 = require("@copilotkitnext/react");
1803
+ var import_react28 = require("react");
1804
+ var import_react29 = require("@copilotkitnext/react");
1767
1805
  function useCoAgent(options) {
1768
- const { agent } = (0, import_react26.useAgent)({ agentId: options.name });
1769
- const nodeNameRef = (0, import_react25.useRef)("start");
1770
- const handleStateUpdate = (0, import_react25.useCallback)(
1806
+ const { agent } = (0, import_react29.useAgent)({ agentId: options.name });
1807
+ const { copilotkit } = (0, import_react29.useCopilotKit)();
1808
+ const nodeName = useAgentNodeName(options.name);
1809
+ const handleStateUpdate = (0, import_react28.useCallback)(
1771
1810
  (newState) => {
1772
1811
  if (!agent)
1773
1812
  return;
@@ -1780,22 +1819,34 @@ function useCoAgent(options) {
1780
1819
  },
1781
1820
  [agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
1782
1821
  );
1783
- const externalStateStr = (0, import_react25.useMemo)(
1822
+ (0, import_react28.useEffect)(() => {
1823
+ var _a;
1824
+ if (!options.config && !options.configurable)
1825
+ return;
1826
+ let config = (_a = options.config) != null ? _a : {};
1827
+ if (options.configurable) {
1828
+ config = __spreadProps(__spreadValues({}, config), {
1829
+ configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
1830
+ });
1831
+ }
1832
+ copilotkit.setProperties(config);
1833
+ }, [options.config, options.configurable]);
1834
+ const externalStateStr = (0, import_react28.useMemo)(
1784
1835
  () => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
1785
1836
  [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
1786
1837
  );
1787
- (0, import_react25.useEffect)(() => {
1838
+ (0, import_react28.useEffect)(() => {
1788
1839
  if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
1789
1840
  handleStateUpdate(options.state);
1790
1841
  }
1791
1842
  }, [agent, externalStateStr, handleStateUpdate]);
1792
- const hasStateValues = (0, import_react25.useCallback)((value) => {
1843
+ const hasStateValues = (0, import_react28.useCallback)((value) => {
1793
1844
  return Boolean(value && Object.keys(value).length);
1794
1845
  }, []);
1795
- const initialStateRef = (0, import_react25.useRef)(
1846
+ const initialStateRef = (0, import_react28.useRef)(
1796
1847
  isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
1797
1848
  );
1798
- (0, import_react25.useEffect)(() => {
1849
+ (0, import_react28.useEffect)(() => {
1799
1850
  if (isExternalStateManagement(options)) {
1800
1851
  initialStateRef.current = options.state;
1801
1852
  } else if ("initialState" in options) {
@@ -1804,7 +1855,7 @@ function useCoAgent(options) {
1804
1855
  }, [
1805
1856
  isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
1806
1857
  ]);
1807
- (0, import_react25.useEffect)(() => {
1858
+ (0, import_react28.useEffect)(() => {
1808
1859
  if (!agent)
1809
1860
  return;
1810
1861
  const subscriber = {
@@ -1825,15 +1876,6 @@ function useCoAgent(options) {
1825
1876
  if (initialStateRef.current !== void 0) {
1826
1877
  handleStateUpdate(initialStateRef.current);
1827
1878
  }
1828
- },
1829
- onStepStartedEvent: ({ event }) => {
1830
- nodeNameRef.current = event.stepName;
1831
- },
1832
- onRunStartedEvent: () => {
1833
- nodeNameRef.current = "start";
1834
- },
1835
- onRunFinishedEvent: () => {
1836
- nodeNameRef.current = "end";
1837
1879
  }
1838
1880
  };
1839
1881
  const subscription = agent.subscribe(subscriber);
@@ -1841,7 +1883,7 @@ function useCoAgent(options) {
1841
1883
  subscription.unsubscribe();
1842
1884
  };
1843
1885
  }, [agent, handleStateUpdate, hasStateValues]);
1844
- return (0, import_react25.useMemo)(() => {
1886
+ return (0, import_react28.useMemo)(() => {
1845
1887
  var _a, _b, _c;
1846
1888
  if (!agent) {
1847
1889
  const noop = () => {
@@ -1857,7 +1899,7 @@ function useCoAgent(options) {
1857
1899
  );
1858
1900
  return {
1859
1901
  name: options.name,
1860
- nodeName: nodeNameRef.current,
1902
+ nodeName,
1861
1903
  threadId: void 0,
1862
1904
  running: false,
1863
1905
  state: initialState,
@@ -1869,7 +1911,7 @@ function useCoAgent(options) {
1869
1911
  }
1870
1912
  return {
1871
1913
  name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
1872
- nodeName: nodeNameRef.current,
1914
+ nodeName,
1873
1915
  threadId: agent.threadId,
1874
1916
  running: agent.isRunning,
1875
1917
  state: agent.state,
@@ -1897,12 +1939,12 @@ var isExternalStateManagement = (options) => {
1897
1939
 
1898
1940
  // src/hooks/use-copilot-runtime-client.ts
1899
1941
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1900
- var import_react27 = require("react");
1942
+ var import_react30 = require("react");
1901
1943
  var import_shared11 = require("@copilotkit/shared");
1902
1944
  var useCopilotRuntimeClient = (options) => {
1903
1945
  const { setBannerError } = useToast();
1904
1946
  const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
1905
- const lastStructuredErrorRef = (0, import_react27.useRef)(null);
1947
+ const lastStructuredErrorRef = (0, import_react30.useRef)(null);
1906
1948
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
1907
1949
  try {
1908
1950
  const errorEvent = {
@@ -1928,7 +1970,7 @@ var useCopilotRuntimeClient = (options) => {
1928
1970
  console.error("Error in onError handler:", error2);
1929
1971
  }
1930
1972
  });
1931
- const runtimeClient = (0, import_react27.useMemo)(() => {
1973
+ const runtimeClient = (0, import_react30.useMemo)(() => {
1932
1974
  return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
1933
1975
  handleGQLErrors: (error) => {
1934
1976
  var _a2;
@@ -2007,28 +2049,28 @@ function createStructuredError(gqlError) {
2007
2049
  }
2008
2050
 
2009
2051
  // src/hooks/use-copilot-authenticated-action.ts
2010
- var import_react28 = require("react");
2011
- var import_react29 = __toESM(require("react"));
2052
+ var import_react31 = require("react");
2053
+ var import_react32 = __toESM(require("react"));
2012
2054
  function useCopilotAuthenticatedAction_c(action, dependencies) {
2013
2055
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
2014
- const pendingActionRef = (0, import_react28.useRef)(null);
2015
- const executeAction = (0, import_react28.useCallback)(
2056
+ const pendingActionRef = (0, import_react31.useRef)(null);
2057
+ const executeAction = (0, import_react31.useCallback)(
2016
2058
  (props) => {
2017
2059
  if (typeof action.render === "function") {
2018
2060
  return action.render(props);
2019
2061
  }
2020
- return action.render || import_react29.default.createElement(import_react28.Fragment);
2062
+ return action.render || import_react32.default.createElement(import_react31.Fragment);
2021
2063
  },
2022
2064
  [action]
2023
2065
  );
2024
- const wrappedRender = (0, import_react28.useCallback)(
2066
+ const wrappedRender = (0, import_react31.useCallback)(
2025
2067
  (props) => {
2026
2068
  const isAuthenticated = Object.values(authStates_c || {}).some(
2027
2069
  (state) => state.status === "authenticated"
2028
2070
  );
2029
2071
  if (!isAuthenticated) {
2030
2072
  pendingActionRef.current = props;
2031
- return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react29.default.createElement(authConfig_c.SignInComponent, {
2073
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react32.default.createElement(authConfig_c.SignInComponent, {
2032
2074
  onSignInComplete: (authState) => {
2033
2075
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2034
2076
  if (pendingActionRef.current) {
@@ -2036,7 +2078,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2036
2078
  pendingActionRef.current = null;
2037
2079
  }
2038
2080
  }
2039
- }) : import_react29.default.createElement(import_react28.Fragment);
2081
+ }) : import_react32.default.createElement(import_react31.Fragment);
2040
2082
  }
2041
2083
  return executeAction(props);
2042
2084
  },
@@ -2051,16 +2093,16 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2051
2093
  }
2052
2094
 
2053
2095
  // src/hooks/use-langgraph-interrupt.ts
2054
- var import_react30 = require("react");
2096
+ var import_react33 = require("react");
2055
2097
  var import_shared12 = require("@copilotkit/shared");
2056
2098
  function useLangGraphInterrupt(action, dependencies) {
2057
- const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react30.useContext)(CopilotContext);
2099
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react33.useContext)(CopilotContext);
2058
2100
  const { addToast } = useToast();
2059
- const actionId = (0, import_shared12.dataToUUID)(JSON.stringify(action), "lgAction");
2060
- (0, import_react30.useEffect)(() => {
2101
+ const actionId = (0, import_shared12.dataToUUID)(action, "lgAction");
2102
+ (0, import_react33.useEffect)(() => {
2061
2103
  if (!action)
2062
2104
  return;
2063
- setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
2105
+ setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
2064
2106
  return () => {
2065
2107
  removeInterruptAction(actionId);
2066
2108
  };
@@ -2068,10 +2110,10 @@ function useLangGraphInterrupt(action, dependencies) {
2068
2110
  }
2069
2111
 
2070
2112
  // src/hooks/use-copilot-additional-instructions.ts
2071
- var import_react31 = require("react");
2113
+ var import_react34 = require("react");
2072
2114
  function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
2073
2115
  const { setAdditionalInstructions } = useCopilotContext();
2074
- (0, import_react31.useEffect)(() => {
2116
+ (0, import_react34.useEffect)(() => {
2075
2117
  if (available === "disabled")
2076
2118
  return;
2077
2119
  setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);