@copilotkit/react-core 1.50.0-beta.0 → 1.50.0-beta.10

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 (201) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/dist/{chunk-UJBV5GAG.mjs → chunk-3775VM7Y.mjs} +32 -65
  3. package/dist/chunk-3775VM7Y.mjs.map +1 -0
  4. package/dist/{chunk-3GURHDG7.mjs → chunk-4HRUQH6U.mjs} +3 -3
  5. package/dist/{chunk-7BYHZLPL.mjs → chunk-4RRMC7L2.mjs} +4 -4
  6. package/dist/chunk-4RRMC7L2.mjs.map +1 -0
  7. package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
  8. package/dist/{chunk-GMI4KO4X.mjs → chunk-7SHWECGN.mjs} +2 -2
  9. package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
  10. package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
  11. package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
  12. package/dist/{chunk-JRT5BJF3.mjs → chunk-B5ELMVT7.mjs} +2 -2
  13. package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
  14. package/dist/{chunk-DCHSCK62.mjs → chunk-FYMZKPOL.mjs} +36 -42
  15. package/dist/chunk-FYMZKPOL.mjs.map +1 -0
  16. package/dist/{chunk-FBD24VEH.mjs → chunk-HE22TZMF.mjs} +2 -2
  17. package/dist/{chunk-FBD24VEH.mjs.map → chunk-HE22TZMF.mjs.map} +1 -1
  18. package/dist/chunk-I76HKHPJ.mjs +32 -0
  19. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  20. package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
  21. package/dist/{chunk-NROJOTQP.mjs → chunk-QNUAXSDP.mjs} +9 -6
  22. package/dist/chunk-QNUAXSDP.mjs.map +1 -0
  23. package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
  24. package/dist/chunk-T2VBHAAP.mjs.map +1 -0
  25. package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
  26. package/dist/{chunk-R4MR43UQ.mjs → chunk-VV56AVPB.mjs} +33 -9
  27. package/dist/chunk-VV56AVPB.mjs.map +1 -0
  28. package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
  29. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  30. package/dist/chunk-XDFVCQD3.mjs +27 -0
  31. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  32. package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
  33. package/dist/{chunk-3R423LZT.mjs → chunk-YJGPIN3R.mjs} +3 -3
  34. package/dist/{chunk-BR5YEYZJ.mjs → chunk-YTQHRJUA.mjs} +2 -2
  35. package/dist/chunk-Z6JV2LRY.mjs +37 -0
  36. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  37. package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
  38. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  39. package/dist/components/CopilotListeners.js +13 -146
  40. package/dist/components/CopilotListeners.js.map +1 -1
  41. package/dist/components/CopilotListeners.mjs +1 -6
  42. package/dist/components/copilot-provider/copilot-messages.js +1 -1
  43. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  44. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  45. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  46. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  47. package/dist/components/copilot-provider/copilotkit.js +35 -40
  48. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  49. package/dist/components/copilot-provider/copilotkit.mjs +9 -9
  50. package/dist/components/copilot-provider/index.d.ts +1 -1
  51. package/dist/components/copilot-provider/index.js +35 -40
  52. package/dist/components/copilot-provider/index.js.map +1 -1
  53. package/dist/components/copilot-provider/index.mjs +9 -9
  54. package/dist/components/dev-console/console-trigger.js +1 -1
  55. package/dist/components/dev-console/console-trigger.js.map +1 -1
  56. package/dist/components/dev-console/console-trigger.mjs +3 -3
  57. package/dist/components/dev-console/developer-console-modal.js +1 -1
  58. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  59. package/dist/components/dev-console/developer-console-modal.mjs +2 -2
  60. package/dist/components/index.d.ts +1 -1
  61. package/dist/components/index.js +35 -40
  62. package/dist/components/index.js.map +1 -1
  63. package/dist/components/index.mjs +9 -9
  64. package/dist/context/copilot-context.d.ts +1 -1
  65. package/dist/context/copilot-context.js +1 -1
  66. package/dist/context/copilot-context.js.map +1 -1
  67. package/dist/context/copilot-context.mjs +1 -1
  68. package/dist/context/index.d.ts +1 -1
  69. package/dist/context/index.js +1 -1
  70. package/dist/context/index.js.map +1 -1
  71. package/dist/context/index.mjs +1 -1
  72. package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-ec77e921.d.ts} +3 -3
  73. package/dist/hooks/index.d.ts +2 -2
  74. package/dist/hooks/index.js +254 -219
  75. package/dist/hooks/index.js.map +1 -1
  76. package/dist/hooks/index.mjs +24 -23
  77. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  78. package/dist/hooks/use-agent-nodename.js +56 -0
  79. package/dist/hooks/use-agent-nodename.js.map +1 -0
  80. package/dist/hooks/use-agent-nodename.mjs +8 -0
  81. package/dist/hooks/use-coagent-state-render-bridge.js +8 -5
  82. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
  83. package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
  84. package/dist/hooks/use-coagent-state-render.js +1 -1
  85. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  86. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  87. package/dist/hooks/use-coagent.js +58 -21
  88. package/dist/hooks/use-coagent.js.map +1 -1
  89. package/dist/hooks/use-coagent.mjs +2 -1
  90. package/dist/hooks/use-copilot-action.js +5 -1
  91. package/dist/hooks/use-copilot-action.js.map +1 -1
  92. package/dist/hooks/use-copilot-action.mjs +2 -2
  93. package/dist/hooks/use-copilot-additional-instructions.js +1 -1
  94. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  95. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  96. package/dist/hooks/use-copilot-authenticated-action.js +6 -2
  97. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  98. package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
  99. package/dist/hooks/use-copilot-chat-headless_c.js +128 -140
  100. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  101. package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
  102. package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
  103. package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
  104. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  105. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  106. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
  107. package/dist/hooks/use-copilot-chat.js +126 -138
  108. package/dist/hooks/use-copilot-chat.js.map +1 -1
  109. package/dist/hooks/use-copilot-chat.mjs +6 -6
  110. package/dist/hooks/use-copilot-chat_internal.d.ts +18 -1
  111. package/dist/hooks/use-copilot-chat_internal.js +126 -138
  112. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  113. package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
  114. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  115. package/dist/hooks/use-copilot-readable.js +29 -5
  116. package/dist/hooks/use-copilot-readable.js.map +1 -1
  117. package/dist/hooks/use-copilot-readable.mjs +1 -1
  118. package/dist/hooks/use-default-tool.js +5 -1
  119. package/dist/hooks/use-default-tool.js.map +1 -1
  120. package/dist/hooks/use-default-tool.mjs +3 -3
  121. package/dist/hooks/use-frontend-tool.js +5 -1
  122. package/dist/hooks/use-frontend-tool.js.map +1 -1
  123. package/dist/hooks/use-frontend-tool.mjs +1 -1
  124. package/dist/hooks/use-langgraph-interrupt-render.js +77 -13
  125. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  126. package/dist/hooks/use-langgraph-interrupt-render.mjs +3 -2
  127. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  128. package/dist/hooks/use-langgraph-interrupt.js +3 -3
  129. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  130. package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
  131. package/dist/hooks/use-make-copilot-document-readable.js +1 -1
  132. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  133. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  134. package/dist/index.d.ts +2 -2
  135. package/dist/index.js +273 -246
  136. package/dist/index.js.map +1 -1
  137. package/dist/index.mjs +34 -33
  138. package/dist/lib/copilot-task.d.ts +1 -1
  139. package/dist/lib/copilot-task.js.map +1 -1
  140. package/dist/lib/copilot-task.mjs +10 -10
  141. package/dist/lib/index.d.ts +1 -1
  142. package/dist/lib/index.js.map +1 -1
  143. package/dist/lib/index.mjs +10 -10
  144. package/dist/types/index.d.ts +1 -1
  145. package/dist/types/interrupt-action.d.ts +1 -1
  146. package/dist/types/interrupt-action.js.map +1 -1
  147. package/dist/utils/index.mjs +3 -3
  148. package/dist/v2/index.css +4 -0
  149. package/dist/v2/index.css.map +1 -0
  150. package/dist/v2/index.js.map +1 -1
  151. package/dist/v2/index.mjs +2 -0
  152. package/dist/v2/index.mjs.map +1 -1
  153. package/jest.config.js +12 -0
  154. package/package.json +27 -24
  155. package/src/components/CopilotListeners.tsx +1 -2
  156. package/src/components/copilot-provider/copilot-messages.tsx +0 -41
  157. package/src/components/copilot-provider/copilotkit.tsx +31 -31
  158. package/src/context/copilot-context.tsx +2 -2
  159. package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
  160. package/src/hooks/index.ts +2 -2
  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-copilot-chat-suggestions.tsx +124 -0
  165. package/src/hooks/use-copilot-chat_internal.ts +78 -78
  166. package/src/hooks/use-copilot-readable.ts +30 -12
  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 +0 -48
  177. package/dist/chunk-CB7CRBDG.mjs.map +0 -1
  178. package/dist/chunk-DCHSCK62.mjs.map +0 -1
  179. package/dist/chunk-IUSKVYUI.mjs +0 -13
  180. package/dist/chunk-IUSKVYUI.mjs.map +0 -1
  181. package/dist/chunk-NG26QEGF.mjs.map +0 -1
  182. package/dist/chunk-NROJOTQP.mjs.map +0 -1
  183. package/dist/chunk-R4MR43UQ.mjs.map +0 -1
  184. package/dist/chunk-UJBV5GAG.mjs.map +0 -1
  185. package/dist/hooks/use-configure-chat-suggestions.js +0 -210
  186. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  187. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -13
  188. package/src/hooks/use-configure-chat-suggestions.tsx +0 -85
  189. /package/dist/{chunk-3GURHDG7.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
  190. /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
  191. /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  192. /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
  193. /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  194. /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
  195. /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
  196. /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
  197. /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
  198. /package/dist/{chunk-3R423LZT.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  199. /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
  200. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-agent-nodename.mjs.map} +0 -0
  201. /package/src/v2/{styles.css → index.css} +0 -0
@@ -81,13 +81,13 @@ var hooks_exports = {};
81
81
  __export(hooks_exports, {
82
82
  useCoAgent: () => useCoAgent,
83
83
  useCoAgentStateRender: () => useCoAgentStateRender,
84
- useConfigureChatSuggestions: () => useConfigureChatSuggestions,
85
84
  useCopilotAction: () => useCopilotAction,
86
85
  useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
87
86
  useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
88
87
  useCopilotChat: () => useCopilotChat,
89
88
  useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
90
89
  useCopilotChatInternal: () => useCopilotChatInternal,
90
+ useCopilotChatSuggestions: () => useCopilotChatSuggestions,
91
91
  useCopilotReadable: () => useCopilotReadable,
92
92
  useCopilotRuntimeClient: () => useCopilotRuntimeClient,
93
93
  useDefaultTool: () => useDefaultTool,
@@ -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_react13 = 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_react14 = 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))
@@ -471,39 +518,7 @@ function useLazyToolRenderer() {
471
518
  );
472
519
  }
473
520
 
474
- // src/hooks/use-configure-chat-suggestions.tsx
475
- var import_react8 = require("@copilotkitnext/react");
476
- var import_react9 = require("react");
477
- function useConfigureChatSuggestions(config, dependencies = []) {
478
- const { agentSession } = useCopilotContext();
479
- const { copilotkit } = (0, import_react8.useCopilotKit)();
480
- const available = config.available === "enabled" ? "always" : config.available;
481
- const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
482
- available,
483
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
484
- // Use chatConfig.agentId here
485
- });
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)(() => {
489
- if (finalSuggestionConfig.available === "disabled")
490
- return;
491
- const subscription = copilotkit.subscribe({
492
- onAgentsChanged: () => {
493
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
494
- if (agent && !agent.isRunning && !result.suggestions.length) {
495
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
496
- }
497
- }
498
- });
499
- return () => {
500
- subscription.unsubscribe();
501
- };
502
- }, []);
503
- return result;
504
- }
505
-
506
- // ../../node_modules/.pnpm/@ag-ui+core@0.0.42-alpha.1/node_modules/@ag-ui/core/dist/index.mjs
521
+ // ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
507
522
  var import_zod = require("zod");
508
523
  var import_zod2 = require("zod");
509
524
  var FunctionCallSchema = import_zod.z.object({
@@ -909,10 +924,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
909
924
  ]);
910
925
 
911
926
  // src/hooks/use-coagent-state-render-bridge.tsx
912
- var import_react10 = require("@copilotkitnext/react");
913
- var import_react11 = require("react");
927
+ var import_react11 = require("@copilotkitnext/react");
928
+ var import_react12 = require("react");
914
929
  var import_shared3 = require("@copilotkit/shared");
915
930
  function getStateWithoutConstantKeys(state) {
931
+ if (!state)
932
+ return {};
916
933
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
917
934
  return stateWithoutConstantKeys;
918
935
  }
@@ -935,11 +952,11 @@ function useCoagentStateRenderBridge(agentId, props) {
935
952
  var _a;
936
953
  const { stateSnapshot, messageIndexInRun, message } = props;
937
954
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
938
- const { agent } = (0, import_react10.useAgent)({ agentId });
939
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
955
+ const { agent } = (0, import_react11.useAgent)({ agentId });
956
+ const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
940
957
  const runId = (_a = props.runId) != null ? _a : message.runId;
941
958
  const effectiveRunId = runId || "pending";
942
- (0, import_react11.useEffect)(() => {
959
+ (0, import_react12.useEffect)(() => {
943
960
  if (!agent)
944
961
  return;
945
962
  const subscriber = {
@@ -959,10 +976,7 @@ function useCoagentStateRenderBridge(agentId, props) {
959
976
  unsubscribe();
960
977
  };
961
978
  }, [agentId, nodeName]);
962
- if (messageIndexInRun !== 0) {
963
- return null;
964
- }
965
- const getStateRender = (0, import_react11.useCallback)(
979
+ const getStateRender = (0, import_react12.useCallback)(
966
980
  (messageId) => {
967
981
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
968
982
  if (claimsRef.current[messageId]) {
@@ -989,7 +1003,7 @@ function useCoagentStateRenderBridge(agentId, props) {
989
1003
  return canRender;
990
1004
  }
991
1005
  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)))
1006
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
993
1007
  );
994
1008
  if (renderClaimedByOtherMessage) {
995
1009
  if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
@@ -1004,8 +1018,11 @@ function useCoagentStateRenderBridge(agentId, props) {
1004
1018
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1005
1019
  return true;
1006
1020
  };
1007
- return (0, import_react11.useMemo)(() => {
1021
+ return (0, import_react12.useMemo)(() => {
1008
1022
  var _a2, _b, _c;
1023
+ if (messageIndexInRun !== 0) {
1024
+ return null;
1025
+ }
1009
1026
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
1010
1027
  if (!stateRender || !stateRenderId) {
1011
1028
  return null;
@@ -1052,7 +1069,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1052
1069
  agent == null ? void 0 : agent.isRunning,
1053
1070
  nodeName,
1054
1071
  effectiveRunId,
1055
- message.id
1072
+ message.id,
1073
+ messageIndexInRun
1056
1074
  ]);
1057
1075
  }
1058
1076
  function CoAgentStateRenderBridge(props) {
@@ -1060,35 +1078,17 @@ function CoAgentStateRenderBridge(props) {
1060
1078
  }
1061
1079
 
1062
1080
  // src/hooks/use-copilot-chat_internal.ts
1063
- function useConfigureSuggestions2(suggestions) {
1064
- let suggestionsConfig;
1065
- if (Array.isArray(suggestions)) {
1066
- suggestionsConfig = {
1067
- suggestions,
1068
- available: "always"
1069
- };
1070
- } else if (suggestions === "auto") {
1071
- suggestionsConfig = {
1072
- available: suggestions === "auto" ? "always" : "disabled",
1073
- instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
1074
- };
1075
- } else {
1076
- suggestionsConfig = { available: "disabled" };
1077
- }
1078
- useConfigureChatSuggestions(suggestionsConfig);
1079
- }
1080
1081
  function useCopilotChatInternal({
1081
1082
  suggestions
1082
1083
  } = {}) {
1083
- var _a, _b, _c, _d;
1084
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1084
+ var _a, _b, _c;
1085
+ const { copilotkit } = (0, import_react14.useCopilotKit)();
1085
1086
  const { threadId, agentSession } = useCopilotContext();
1086
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1087
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1088
- 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)(() => {
1087
+ const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
1088
+ const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
1089
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1090
+ const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
1091
+ (0, import_react13.useEffect)(() => {
1092
1092
  const connect = (agent2) => __async(this, null, function* () {
1093
1093
  setAgentAvailable(false);
1094
1094
  try {
@@ -1113,7 +1113,7 @@ function useCopilotChatInternal({
1113
1113
  agent == null ? void 0 : agent.setMessages([]);
1114
1114
  agent == null ? void 0 : agent.setState(null);
1115
1115
  };
1116
- const deleteMessage = (0, import_react12.useCallback)(
1116
+ const deleteMessage = (0, import_react13.useCallback)(
1117
1117
  (messageId) => {
1118
1118
  var _a2;
1119
1119
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1124,13 +1124,13 @@ function useCopilotChatInternal({
1124
1124
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1125
1125
  );
1126
1126
  const latestDelete = useUpdatedRef(deleteMessage);
1127
- const latestDeleteFunc = (0, import_react12.useCallback)(
1127
+ const latestDeleteFunc = (0, import_react13.useCallback)(
1128
1128
  (messageId) => {
1129
1129
  return latestDelete.current(messageId);
1130
1130
  },
1131
1131
  [latestDelete]
1132
1132
  );
1133
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1133
+ const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
1134
1134
  const reload = useAsyncCallback(
1135
1135
  (reloadMessageId) => __async(this, null, function* () {
1136
1136
  var _a2;
@@ -1197,16 +1197,15 @@ function useCopilotChatInternal({
1197
1197
  }),
1198
1198
  [latestSendMessageFunc]
1199
1199
  );
1200
- const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1201
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1200
+ const latestSetMessagesFunc = (0, import_react13.useCallback)(
1202
1201
  (messages) => {
1203
1202
  var _a2, _b2;
1204
1203
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
1205
- return (_a2 = latestSetMessages.current) == null ? void 0 : _a2.call(latestSetMessages, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
1204
+ return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
1206
1205
  }
1207
- return (_b2 = latestSetMessages.current) == null ? void 0 : _b2.call(latestSetMessages, messages);
1206
+ return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
1208
1207
  },
1209
- [latestSetMessages, agent]
1208
+ [agent == null ? void 0 : agent.setMessages, agent]
1210
1209
  );
1211
1210
  const latestReload = useUpdatedRef(reload);
1212
1211
  const latestReloadFunc = useAsyncCallback(
@@ -1215,25 +1214,24 @@ function useCopilotChatInternal({
1215
1214
  }),
1216
1215
  [latestReload]
1217
1216
  );
1218
- const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1219
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1217
+ const latestStopFunc = (0, import_react13.useCallback)(() => {
1220
1218
  var _a2;
1221
- return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1222
- }, [latestStop]);
1219
+ return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
1220
+ }, [agent == null ? void 0 : agent.abortRun]);
1223
1221
  const latestReset = useUpdatedRef(reset);
1224
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1222
+ const latestResetFunc = (0, import_react13.useCallback)(() => {
1225
1223
  return latestReset.current();
1226
1224
  }, [latestReset]);
1227
1225
  const lazyToolRendered = useLazyToolRenderer();
1228
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1226
+ const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
1229
1227
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1230
1228
  copilotkit,
1231
1229
  agent,
1232
1230
  agentId: resolvedAgentId,
1233
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1231
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1234
1232
  });
1235
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1236
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1233
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1234
+ const resolvedMessages = (0, import_react13.useMemo)(() => {
1237
1235
  let processedMessages = allMessages.map((message) => {
1238
1236
  if (message.role !== "assistant") {
1239
1237
  return message;
@@ -1261,33 +1259,24 @@ function useCopilotChatInternal({
1261
1259
  return message;
1262
1260
  });
1263
1261
  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
1262
  return processedMessages;
1283
1263
  }, [
1284
1264
  agent == null ? void 0 : agent.messages,
1285
1265
  lazyToolRendered,
1286
1266
  allMessages,
1287
1267
  renderCustomMessage,
1288
- legacyCustomMessageRenderer,
1268
+ // legacyCustomMessageRenderer,
1289
1269
  resolvedAgentId
1290
1270
  ]);
1271
+ const renderedSuggestions = (0, import_react13.useMemo)(() => {
1272
+ if (Array.isArray(suggestions)) {
1273
+ return {
1274
+ suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
1275
+ isLoading: false
1276
+ };
1277
+ }
1278
+ return currentSuggestions;
1279
+ }, [suggestions, currentSuggestions]);
1291
1280
  return {
1292
1281
  messages: resolvedMessages,
1293
1282
  sendMessage: latestSendMessageFunc,
@@ -1297,25 +1286,25 @@ function useCopilotChatInternal({
1297
1286
  stopGeneration: latestStopFunc,
1298
1287
  reset: latestResetFunc,
1299
1288
  deleteMessage: latestDeleteFunc,
1300
- isAvailable: !agentAvailable,
1289
+ isAvailable: agentAvailable,
1301
1290
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1302
1291
  // mcpServers,
1303
1292
  // setMcpServers,
1304
- suggestions: currentSuggestions.suggestions,
1293
+ suggestions: renderedSuggestions.suggestions,
1305
1294
  setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
1306
1295
  generateSuggestions: () => __async(this, null, function* () {
1307
1296
  return copilotkit.reloadSuggestions(resolvedAgentId);
1308
1297
  }),
1309
1298
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
1310
- isLoadingSuggestions: currentSuggestions.isLoading,
1299
+ isLoadingSuggestions: renderedSuggestions.isLoading,
1311
1300
  interrupt,
1312
1301
  agent,
1313
1302
  threadId
1314
1303
  };
1315
1304
  }
1316
1305
  function useUpdatedRef(value) {
1317
- const ref = (0, import_react12.useRef)(value);
1318
- (0, import_react12.useEffect)(() => {
1306
+ const ref = (0, import_react13.useRef)(value);
1307
+ (0, import_react13.useEffect)(() => {
1319
1308
  ref.current = value;
1320
1309
  }, [value]);
1321
1310
  return ref;
@@ -1326,20 +1315,19 @@ function useLegacyCoagentRenderer({
1326
1315
  agentId,
1327
1316
  threadId
1328
1317
  }) {
1329
- return (0, import_react12.useMemo)(() => {
1318
+ return (0, import_react13.useMemo)(() => {
1330
1319
  if (!copilotkit || !agent) {
1331
1320
  return null;
1332
1321
  }
1333
1322
  return ({ message, position }) => {
1334
1323
  var _a;
1335
1324
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1336
- const existingRunId = copilotkit.getRunIdForMessage(
1337
- agentId,
1338
- effectiveThreadId,
1339
- message.id
1340
- );
1325
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1341
1326
  const runId = existingRunId || `pending:${message.id}`;
1342
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1327
+ const messageIndex = Math.max(
1328
+ agent.messages.findIndex((msg) => msg.id === message.id),
1329
+ 0
1330
+ );
1343
1331
  const bridgeProps = {
1344
1332
  message,
1345
1333
  position,
@@ -1350,7 +1338,7 @@ function useLegacyCoagentRenderer({
1350
1338
  agentId,
1351
1339
  stateSnapshot: message.state
1352
1340
  };
1353
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1341
+ return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
1354
1342
  };
1355
1343
  }, [agent, agentId, copilotkit, threadId]);
1356
1344
  }
@@ -1384,7 +1372,7 @@ function useCopilotChat(options = {}) {
1384
1372
  }
1385
1373
 
1386
1374
  // src/hooks/use-copilot-chat-headless_c.ts
1387
- var import_react14 = require("react");
1375
+ var import_react15 = require("react");
1388
1376
  var import_shared4 = require("@copilotkit/shared");
1389
1377
  var createNonFunctionalReturn = () => ({
1390
1378
  visibleMessages: [],
@@ -1425,7 +1413,7 @@ function useCopilotChatHeadless_c(options = {}) {
1425
1413
  const { copilotApiConfig, setBannerError } = useCopilotContext();
1426
1414
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
1427
1415
  const internalResult = useCopilotChatInternal(options);
1428
- (0, import_react14.useEffect)(() => {
1416
+ (0, import_react15.useEffect)(() => {
1429
1417
  if (!hasPublicApiKey) {
1430
1418
  setBannerError(
1431
1419
  new import_shared4.CopilotKitError({
@@ -1450,13 +1438,13 @@ function useCopilotChatHeadless_c(options = {}) {
1450
1438
  }
1451
1439
 
1452
1440
  // src/hooks/use-copilot-action.ts
1453
- var import_react21 = require("react");
1441
+ var import_react22 = require("react");
1454
1442
 
1455
1443
  // src/hooks/use-frontend-tool.ts
1456
- var import_react15 = __toESM(require("react"));
1444
+ var import_react16 = __toESM(require("react"));
1457
1445
  var import_shared5 = require("@copilotkit/shared");
1458
1446
  var import_shared6 = require("@copilotkit/shared");
1459
- var import_react16 = require("@copilotkitnext/react");
1447
+ var import_react17 = require("@copilotkitnext/react");
1460
1448
  function useFrontendTool(tool, dependencies) {
1461
1449
  const { name, description, parameters, render, followUp } = tool;
1462
1450
  const zodParameters = (0, import_shared5.getZodParameters)(parameters);
@@ -1466,7 +1454,11 @@ function useFrontendTool(tool, dependencies) {
1466
1454
  }
1467
1455
  if (typeof render === "string") {
1468
1456
  const staticRender = render;
1469
- return () => import_react15.default.createElement(import_react15.default.Fragment, null, staticRender);
1457
+ return () => import_react16.default.createElement(
1458
+ import_react16.default.Fragment,
1459
+ null,
1460
+ staticRender
1461
+ );
1470
1462
  }
1471
1463
  return (args) => {
1472
1464
  const renderArgs = __spreadProps(__spreadValues({}, args), {
@@ -1474,12 +1466,12 @@ function useFrontendTool(tool, dependencies) {
1474
1466
  });
1475
1467
  const rendered = render(renderArgs);
1476
1468
  if (typeof rendered === "string") {
1477
- return import_react15.default.createElement(import_react15.default.Fragment, null, rendered);
1469
+ return import_react16.default.createElement(import_react16.default.Fragment, null, rendered);
1478
1470
  }
1479
1471
  return rendered != null ? rendered : null;
1480
1472
  };
1481
1473
  })();
1482
- (0, import_react16.useFrontendTool)({
1474
+ (0, import_react17.useFrontendTool)({
1483
1475
  name,
1484
1476
  description,
1485
1477
  parameters: zodParameters,
@@ -1491,23 +1483,23 @@ function useFrontendTool(tool, dependencies) {
1491
1483
 
1492
1484
  // src/hooks/use-render-tool-call.ts
1493
1485
  var import_shared7 = require("@copilotkit/shared");
1494
- var import_react17 = require("react");
1495
- var import_react18 = require("@copilotkitnext/react");
1486
+ var import_react18 = require("react");
1487
+ var import_react19 = require("@copilotkitnext/react");
1496
1488
  var import_shared8 = require("@copilotkit/shared");
1497
1489
  function useRenderToolCall2(tool, dependencies) {
1498
- const { copilotkit } = (0, import_react18.useCopilotKit)();
1499
- const hasAddedRef = (0, import_react17.useRef)(false);
1500
- (0, import_react17.useEffect)(() => {
1490
+ const { copilotkit } = (0, import_react19.useCopilotKit)();
1491
+ const hasAddedRef = (0, import_react18.useRef)(false);
1492
+ (0, import_react18.useEffect)(() => {
1501
1493
  const { name, parameters, render } = tool;
1502
1494
  const zodParameters = (0, import_shared7.getZodParameters)(parameters);
1503
- const renderToolCall = name === "*" ? (0, import_react18.defineToolCallRenderer)({
1495
+ const renderToolCall = name === "*" ? (0, import_react19.defineToolCallRenderer)({
1504
1496
  name: "*",
1505
1497
  render: (args) => {
1506
1498
  return render(__spreadProps(__spreadValues({}, args), {
1507
1499
  result: args.result ? (0, import_shared8.parseJson)(args.result, args.result) : args.result
1508
1500
  }));
1509
1501
  }
1510
- }) : (0, import_react18.defineToolCallRenderer)({
1502
+ }) : (0, import_react19.defineToolCallRenderer)({
1511
1503
  name,
1512
1504
  args: zodParameters,
1513
1505
  render: (args) => {
@@ -1536,18 +1528,18 @@ function useRenderToolCall2(tool, dependencies) {
1536
1528
 
1537
1529
  // src/hooks/use-human-in-the-loop.ts
1538
1530
  var import_shared9 = require("@copilotkit/shared");
1539
- var import_react19 = require("@copilotkitnext/react");
1531
+ var import_react20 = require("@copilotkitnext/react");
1540
1532
  var import_core = require("@copilotkitnext/core");
1541
- var import_react20 = __toESM(require("react"));
1533
+ var import_react21 = __toESM(require("react"));
1542
1534
  function useHumanInTheLoop(tool, dependencies) {
1543
1535
  const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
1544
1536
  const { name, description, parameters, followUp } = toolRest;
1545
1537
  const zodParameters = (0, import_shared9.getZodParameters)(parameters);
1546
- const renderRef = (0, import_react20.useRef)(null);
1547
- (0, import_react20.useEffect)(() => {
1538
+ const renderRef = (0, import_react21.useRef)(null);
1539
+ (0, import_react21.useEffect)(() => {
1548
1540
  renderRef.current = (args) => {
1549
1541
  if (typeof render === "string") {
1550
- return import_react20.default.createElement(import_react20.default.Fragment, null, render);
1542
+ return import_react21.default.createElement(import_react21.default.Fragment, null, render);
1551
1543
  }
1552
1544
  if (!render) {
1553
1545
  return null;
@@ -1587,12 +1579,12 @@ function useHumanInTheLoop(tool, dependencies) {
1587
1579
  })();
1588
1580
  const rendered = render(renderProps);
1589
1581
  if (typeof rendered === "string") {
1590
- return import_react20.default.createElement(import_react20.default.Fragment, null, rendered);
1582
+ return import_react21.default.createElement(import_react21.default.Fragment, null, rendered);
1591
1583
  }
1592
1584
  return rendered != null ? rendered : null;
1593
1585
  };
1594
1586
  }, [render, ...dependencies != null ? dependencies : []]);
1595
- (0, import_react19.useHumanInTheLoop)({
1587
+ (0, import_react20.useHumanInTheLoop)({
1596
1588
  name,
1597
1589
  description,
1598
1590
  followUp,
@@ -1648,7 +1640,7 @@ function getActionConfig(action) {
1648
1640
  throw new Error("Invalid action configuration");
1649
1641
  }
1650
1642
  function useCopilotAction(action, dependencies) {
1651
- const [initialActionConfig] = (0, import_react21.useState)(getActionConfig(action));
1643
+ const [initialActionConfig] = (0, import_react22.useState)(getActionConfig(action));
1652
1644
  const currentActionConfig = getActionConfig(action);
1653
1645
  if (initialActionConfig.type !== currentActionConfig.type) {
1654
1646
  throw new Error("Action configuration changed between renders");
@@ -1666,14 +1658,14 @@ function useCopilotAction(action, dependencies) {
1666
1658
  }
1667
1659
 
1668
1660
  // src/hooks/use-coagent-state-render.ts
1669
- var import_react22 = require("react");
1661
+ var import_react23 = require("react");
1670
1662
  var import_shared10 = require("@copilotkit/shared");
1671
1663
  function useCoAgentStateRender(action, dependencies) {
1672
- const { chatComponentsCache, availableAgents } = (0, import_react22.useContext)(CopilotContext);
1664
+ const { chatComponentsCache, availableAgents } = (0, import_react23.useContext)(CopilotContext);
1673
1665
  const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
1674
- const idRef = (0, import_react22.useRef)((0, import_shared10.randomId)());
1666
+ const idRef = (0, import_react23.useRef)((0, import_shared10.randomId)());
1675
1667
  const { setBannerError, addToast } = useToast();
1676
- (0, import_react22.useEffect)(() => {
1668
+ (0, import_react23.useEffect)(() => {
1677
1669
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
1678
1670
  const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
1679
1671
  const agentError = new import_shared10.CopilotKitAgentDiscoveryError({
@@ -1694,7 +1686,7 @@ function useCoAgentStateRender(action, dependencies) {
1694
1686
  }
1695
1687
  }
1696
1688
  }
1697
- (0, import_react22.useEffect)(() => {
1689
+ (0, import_react23.useEffect)(() => {
1698
1690
  const currentId = idRef.current;
1699
1691
  const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
1700
1692
  if (id === currentId)
@@ -1718,7 +1710,7 @@ function useCoAgentStateRender(action, dependencies) {
1718
1710
  });
1719
1711
  }
1720
1712
  }, [coAgentStateRenders]);
1721
- (0, import_react22.useEffect)(() => {
1713
+ (0, import_react23.useEffect)(() => {
1722
1714
  setCoAgentStateRender(idRef.current, action);
1723
1715
  if (chatComponentsCache.current !== null && action.render !== void 0) {
1724
1716
  chatComponentsCache.current.coAgentStateRenders[key] = action.render;
@@ -1738,11 +1730,11 @@ function useCoAgentStateRender(action, dependencies) {
1738
1730
  }
1739
1731
 
1740
1732
  // src/hooks/use-make-copilot-document-readable.ts
1741
- var import_react23 = require("react");
1733
+ var import_react24 = require("react");
1742
1734
  function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
1743
1735
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
1744
- const idRef = (0, import_react23.useRef)(void 0);
1745
- (0, import_react23.useEffect)(() => {
1736
+ const idRef = (0, import_react24.useRef)(void 0);
1737
+ (0, import_react24.useEffect)(() => {
1746
1738
  const id = addDocumentContext(document, categories);
1747
1739
  idRef.current = id;
1748
1740
  return () => {
@@ -1753,21 +1745,46 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
1753
1745
  }
1754
1746
 
1755
1747
  // src/hooks/use-copilot-readable.ts
1756
- var import_react24 = require("@copilotkitnext/react");
1757
- function useCopilotReadable({ description, value }, dependencies) {
1758
- (0, import_react24.useAgentContext)({
1759
- description,
1760
- value
1761
- });
1748
+ var import_react25 = require("@copilotkitnext/react");
1749
+ var import_react26 = require("react");
1750
+ function useCopilotReadable({ description, value, convert, available }, dependencies) {
1751
+ const { copilotkit } = (0, import_react25.useCopilotKit)();
1752
+ const ctxIdRef = (0, import_react26.useRef)(void 0);
1753
+ (0, import_react26.useEffect)(() => {
1754
+ if (!copilotkit)
1755
+ return;
1756
+ const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
1757
+ return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
1758
+ });
1759
+ if (found) {
1760
+ ctxIdRef.current = found[0];
1761
+ if (available === "disabled")
1762
+ copilotkit.removeContext(ctxIdRef.current);
1763
+ return;
1764
+ }
1765
+ if (!found && available === "disabled")
1766
+ return;
1767
+ ctxIdRef.current = copilotkit.addContext({
1768
+ description,
1769
+ value: (convert != null ? convert : JSON.stringify)(value)
1770
+ });
1771
+ return () => {
1772
+ if (!ctxIdRef.current)
1773
+ return;
1774
+ copilotkit.removeContext(ctxIdRef.current);
1775
+ };
1776
+ }, [description, value, convert]);
1777
+ return ctxIdRef.current;
1762
1778
  }
1763
1779
 
1764
1780
  // src/hooks/use-coagent.ts
1765
- var import_react25 = require("react");
1766
- var import_react26 = require("@copilotkitnext/react");
1781
+ var import_react27 = require("react");
1782
+ var import_react28 = require("@copilotkitnext/react");
1767
1783
  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)(
1784
+ const { agent } = (0, import_react28.useAgent)({ agentId: options.name });
1785
+ const { copilotkit } = (0, import_react28.useCopilotKit)();
1786
+ const nodeName = useAgentNodeName(options.name);
1787
+ const handleStateUpdate = (0, import_react27.useCallback)(
1771
1788
  (newState) => {
1772
1789
  if (!agent)
1773
1790
  return;
@@ -1780,22 +1797,34 @@ function useCoAgent(options) {
1780
1797
  },
1781
1798
  [agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
1782
1799
  );
1783
- const externalStateStr = (0, import_react25.useMemo)(
1800
+ (0, import_react27.useEffect)(() => {
1801
+ var _a;
1802
+ if (!options.config && !options.configurable)
1803
+ return;
1804
+ let config = (_a = options.config) != null ? _a : {};
1805
+ if (options.configurable) {
1806
+ config = __spreadProps(__spreadValues({}, config), {
1807
+ configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
1808
+ });
1809
+ }
1810
+ copilotkit.setProperties(config);
1811
+ }, [options.config, options.configurable]);
1812
+ const externalStateStr = (0, import_react27.useMemo)(
1784
1813
  () => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
1785
1814
  [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
1786
1815
  );
1787
- (0, import_react25.useEffect)(() => {
1816
+ (0, import_react27.useEffect)(() => {
1788
1817
  if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
1789
1818
  handleStateUpdate(options.state);
1790
1819
  }
1791
1820
  }, [agent, externalStateStr, handleStateUpdate]);
1792
- const hasStateValues = (0, import_react25.useCallback)((value) => {
1821
+ const hasStateValues = (0, import_react27.useCallback)((value) => {
1793
1822
  return Boolean(value && Object.keys(value).length);
1794
1823
  }, []);
1795
- const initialStateRef = (0, import_react25.useRef)(
1824
+ const initialStateRef = (0, import_react27.useRef)(
1796
1825
  isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
1797
1826
  );
1798
- (0, import_react25.useEffect)(() => {
1827
+ (0, import_react27.useEffect)(() => {
1799
1828
  if (isExternalStateManagement(options)) {
1800
1829
  initialStateRef.current = options.state;
1801
1830
  } else if ("initialState" in options) {
@@ -1804,7 +1833,7 @@ function useCoAgent(options) {
1804
1833
  }, [
1805
1834
  isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
1806
1835
  ]);
1807
- (0, import_react25.useEffect)(() => {
1836
+ (0, import_react27.useEffect)(() => {
1808
1837
  if (!agent)
1809
1838
  return;
1810
1839
  const subscriber = {
@@ -1825,15 +1854,6 @@ function useCoAgent(options) {
1825
1854
  if (initialStateRef.current !== void 0) {
1826
1855
  handleStateUpdate(initialStateRef.current);
1827
1856
  }
1828
- },
1829
- onStepStartedEvent: ({ event }) => {
1830
- nodeNameRef.current = event.stepName;
1831
- },
1832
- onRunStartedEvent: () => {
1833
- nodeNameRef.current = "start";
1834
- },
1835
- onRunFinishedEvent: () => {
1836
- nodeNameRef.current = "end";
1837
1857
  }
1838
1858
  };
1839
1859
  const subscription = agent.subscribe(subscriber);
@@ -1841,7 +1861,7 @@ function useCoAgent(options) {
1841
1861
  subscription.unsubscribe();
1842
1862
  };
1843
1863
  }, [agent, handleStateUpdate, hasStateValues]);
1844
- return (0, import_react25.useMemo)(() => {
1864
+ return (0, import_react27.useMemo)(() => {
1845
1865
  var _a, _b, _c;
1846
1866
  if (!agent) {
1847
1867
  const noop = () => {
@@ -1857,7 +1877,7 @@ function useCoAgent(options) {
1857
1877
  );
1858
1878
  return {
1859
1879
  name: options.name,
1860
- nodeName: nodeNameRef.current,
1880
+ nodeName,
1861
1881
  threadId: void 0,
1862
1882
  running: false,
1863
1883
  state: initialState,
@@ -1869,7 +1889,7 @@ function useCoAgent(options) {
1869
1889
  }
1870
1890
  return {
1871
1891
  name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
1872
- nodeName: nodeNameRef.current,
1892
+ nodeName,
1873
1893
  threadId: agent.threadId,
1874
1894
  running: agent.isRunning,
1875
1895
  state: agent.state,
@@ -1897,12 +1917,12 @@ var isExternalStateManagement = (options) => {
1897
1917
 
1898
1918
  // src/hooks/use-copilot-runtime-client.ts
1899
1919
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1900
- var import_react27 = require("react");
1920
+ var import_react29 = require("react");
1901
1921
  var import_shared11 = require("@copilotkit/shared");
1902
1922
  var useCopilotRuntimeClient = (options) => {
1903
1923
  const { setBannerError } = useToast();
1904
1924
  const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
1905
- const lastStructuredErrorRef = (0, import_react27.useRef)(null);
1925
+ const lastStructuredErrorRef = (0, import_react29.useRef)(null);
1906
1926
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
1907
1927
  try {
1908
1928
  const errorEvent = {
@@ -1928,7 +1948,7 @@ var useCopilotRuntimeClient = (options) => {
1928
1948
  console.error("Error in onError handler:", error2);
1929
1949
  }
1930
1950
  });
1931
- const runtimeClient = (0, import_react27.useMemo)(() => {
1951
+ const runtimeClient = (0, import_react29.useMemo)(() => {
1932
1952
  return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
1933
1953
  handleGQLErrors: (error) => {
1934
1954
  var _a2;
@@ -2007,28 +2027,28 @@ function createStructuredError(gqlError) {
2007
2027
  }
2008
2028
 
2009
2029
  // src/hooks/use-copilot-authenticated-action.ts
2010
- var import_react28 = require("react");
2011
- var import_react29 = __toESM(require("react"));
2030
+ var import_react30 = require("react");
2031
+ var import_react31 = __toESM(require("react"));
2012
2032
  function useCopilotAuthenticatedAction_c(action, dependencies) {
2013
2033
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
2014
- const pendingActionRef = (0, import_react28.useRef)(null);
2015
- const executeAction = (0, import_react28.useCallback)(
2034
+ const pendingActionRef = (0, import_react30.useRef)(null);
2035
+ const executeAction = (0, import_react30.useCallback)(
2016
2036
  (props) => {
2017
2037
  if (typeof action.render === "function") {
2018
2038
  return action.render(props);
2019
2039
  }
2020
- return action.render || import_react29.default.createElement(import_react28.Fragment);
2040
+ return action.render || import_react31.default.createElement(import_react30.Fragment);
2021
2041
  },
2022
2042
  [action]
2023
2043
  );
2024
- const wrappedRender = (0, import_react28.useCallback)(
2044
+ const wrappedRender = (0, import_react30.useCallback)(
2025
2045
  (props) => {
2026
2046
  const isAuthenticated = Object.values(authStates_c || {}).some(
2027
2047
  (state) => state.status === "authenticated"
2028
2048
  );
2029
2049
  if (!isAuthenticated) {
2030
2050
  pendingActionRef.current = props;
2031
- return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react29.default.createElement(authConfig_c.SignInComponent, {
2051
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react31.default.createElement(authConfig_c.SignInComponent, {
2032
2052
  onSignInComplete: (authState) => {
2033
2053
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2034
2054
  if (pendingActionRef.current) {
@@ -2036,7 +2056,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2036
2056
  pendingActionRef.current = null;
2037
2057
  }
2038
2058
  }
2039
- }) : import_react29.default.createElement(import_react28.Fragment);
2059
+ }) : import_react31.default.createElement(import_react30.Fragment);
2040
2060
  }
2041
2061
  return executeAction(props);
2042
2062
  },
@@ -2051,16 +2071,16 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2051
2071
  }
2052
2072
 
2053
2073
  // src/hooks/use-langgraph-interrupt.ts
2054
- var import_react30 = require("react");
2074
+ var import_react32 = require("react");
2055
2075
  var import_shared12 = require("@copilotkit/shared");
2056
2076
  function useLangGraphInterrupt(action, dependencies) {
2057
- const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react30.useContext)(CopilotContext);
2077
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react32.useContext)(CopilotContext);
2058
2078
  const { addToast } = useToast();
2059
- const actionId = (0, import_shared12.dataToUUID)(JSON.stringify(action), "lgAction");
2060
- (0, import_react30.useEffect)(() => {
2079
+ const actionId = (0, import_shared12.dataToUUID)(action, "lgAction");
2080
+ (0, import_react32.useEffect)(() => {
2061
2081
  if (!action)
2062
2082
  return;
2063
- setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
2083
+ setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
2064
2084
  return () => {
2065
2085
  removeInterruptAction(actionId);
2066
2086
  };
@@ -2068,10 +2088,10 @@ function useLangGraphInterrupt(action, dependencies) {
2068
2088
  }
2069
2089
 
2070
2090
  // src/hooks/use-copilot-additional-instructions.ts
2071
- var import_react31 = require("react");
2091
+ var import_react33 = require("react");
2072
2092
  function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
2073
2093
  const { setAdditionalInstructions } = useCopilotContext();
2074
- (0, import_react31.useEffect)(() => {
2094
+ (0, import_react33.useEffect)(() => {
2075
2095
  if (available === "disabled")
2076
2096
  return;
2077
2097
  setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
@@ -2087,17 +2107,32 @@ function useCopilotAdditionalInstructions({ instructions, available = "enabled"
2087
2107
  function useDefaultTool(tool, dependencies) {
2088
2108
  useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
2089
2109
  }
2110
+
2111
+ // src/hooks/use-copilot-chat-suggestions.tsx
2112
+ var import_react34 = require("@copilotkitnext/react");
2113
+ function useCopilotChatSuggestions(config, dependencies = []) {
2114
+ var _a, _b;
2115
+ const existingConfig = (0, import_react34.useCopilotChatConfiguration)();
2116
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
2117
+ const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
2118
+ const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
2119
+ available,
2120
+ consumerAgentId: resolvedAgentId
2121
+ // Use chatConfig.agentId here
2122
+ });
2123
+ (0, import_react34.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
2124
+ }
2090
2125
  // Annotate the CommonJS export names for ESM import in node:
2091
2126
  0 && (module.exports = {
2092
2127
  useCoAgent,
2093
2128
  useCoAgentStateRender,
2094
- useConfigureChatSuggestions,
2095
2129
  useCopilotAction,
2096
2130
  useCopilotAdditionalInstructions,
2097
2131
  useCopilotAuthenticatedAction_c,
2098
2132
  useCopilotChat,
2099
2133
  useCopilotChatHeadless_c,
2100
2134
  useCopilotChatInternal,
2135
+ useCopilotChatSuggestions,
2101
2136
  useCopilotReadable,
2102
2137
  useCopilotRuntimeClient,
2103
2138
  useDefaultTool,