@copilotkit/react-core 1.50.0-beta.1 → 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 +14 -11
  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
@@ -45,6 +45,23 @@ interface UseCopilotChatOptions {
45
45
  * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
46
46
  */
47
47
  disableSystemMessage?: boolean;
48
+ /**
49
+ * Controls the behavior of suggestions in the chat interface.
50
+ *
51
+ * `auto` (default) - Suggestions are generated automatically:
52
+ * - When the chat is first opened (empty state)
53
+ * - After each message exchange completes
54
+ * - Uses configuration from `useCopilotChatSuggestions` hooks
55
+ *
56
+ * `manual` - Suggestions are controlled programmatically:
57
+ * - Use `setSuggestions()` to set custom suggestions
58
+ * - Use `generateSuggestions()` to trigger AI generation
59
+ * - Access via `useCopilotChat` hook
60
+ *
61
+ * `SuggestionItem[]` - Static suggestions array:
62
+ * - Always shows the same suggestions
63
+ * - No AI generation involved
64
+ */
48
65
  suggestions?: ChatSuggestions;
49
66
  }
50
67
  interface MCPServerConfig {
@@ -175,7 +192,7 @@ interface UseCopilotChatReturn {
175
192
  * Manually set suggestions
176
193
  * Useful for manual mode or custom suggestion workflows
177
194
  */
178
- setSuggestions: (suggestions: Suggestion[]) => void;
195
+ setSuggestions: (suggestions: Omit<Suggestion, "isLoading">[]) => void;
179
196
  /**
180
197
  * Trigger AI-powered suggestion generation
181
198
  * Uses configurations from useCopilotChatSuggestions hooks
@@ -83,7 +83,7 @@ __export(use_copilot_chat_internal_exports, {
83
83
  useCopilotChatInternal: () => useCopilotChatInternal
84
84
  });
85
85
  module.exports = __toCommonJS(use_copilot_chat_internal_exports);
86
- var import_react12 = require("react");
86
+ var import_react13 = require("react");
87
87
 
88
88
  // src/context/copilot-context.tsx
89
89
  var import_react = __toESM(require("react"));
@@ -161,7 +161,7 @@ var emptyCopilotContext = {
161
161
  interruptEventQueue: {},
162
162
  addInterruptEvent: () => {
163
163
  },
164
- removeInterruptEvent: () => {
164
+ resolveInterruptEvent: () => {
165
165
  },
166
166
  onError: () => {
167
167
  },
@@ -332,24 +332,60 @@ function useCoAgentStateRenders() {
332
332
  }
333
333
 
334
334
  // src/hooks/use-langgraph-interrupt-render.ts
335
- var import_react5 = __toESM(require("react"));
335
+ var import_react7 = __toESM(require("react"));
336
336
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
337
337
  var import_shared2 = require("@copilotkit/shared");
338
+
339
+ // src/hooks/use-agent-nodename.ts
340
+ var import_react5 = require("react");
341
+ var import_react6 = require("@copilotkitnext/react");
342
+ function useAgentNodeName(agentName) {
343
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
344
+ const nodeNameRef = (0, import_react5.useRef)("start");
345
+ (0, import_react5.useEffect)(() => {
346
+ if (!agent)
347
+ return;
348
+ const subscriber = {
349
+ onStepStartedEvent: ({ event }) => {
350
+ nodeNameRef.current = event.stepName;
351
+ },
352
+ onRunStartedEvent: () => {
353
+ nodeNameRef.current = "start";
354
+ },
355
+ onRunFinishedEvent: () => {
356
+ nodeNameRef.current = "end";
357
+ }
358
+ };
359
+ const subscription = agent.subscribe(subscriber);
360
+ return () => {
361
+ subscription.unsubscribe();
362
+ };
363
+ }, [agent]);
364
+ return nodeNameRef.current;
365
+ }
366
+
367
+ // src/hooks/use-langgraph-interrupt-render.ts
368
+ var import_react8 = require("@copilotkitnext/react");
338
369
  var InterruptRenderer = ({ event, result, render, resolve }) => {
339
370
  return render({ event, result, resolve });
340
371
  };
341
372
  function useLangGraphInterruptRender(agent) {
373
+ var _a;
342
374
  const {
343
375
  interruptActions,
344
376
  agentSession,
345
377
  threadId,
346
378
  interruptEventQueue,
347
379
  addInterruptEvent,
348
- removeInterruptEvent
380
+ resolveInterruptEvent
349
381
  } = useCopilotContext();
350
- (0, import_react5.useEffect)(() => {
382
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
383
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
384
+ const nodeName = useAgentNodeName(resolvedAgentId);
385
+ (0, import_react7.useEffect)(() => {
351
386
  if (!agent)
352
387
  return;
388
+ let localInterrupt = null;
353
389
  const subscriber = {
354
390
  onCustomEvent: ({ event }) => {
355
391
  if (event.name === "on_interrupt") {
@@ -358,12 +394,21 @@ function useLangGraphInterruptRender(agent) {
358
394
  type: event.type,
359
395
  value: (0, import_shared2.parseJson)(event.value, event.value)
360
396
  };
361
- const eventId = (0, import_shared2.dataToUUID)(JSON.stringify(eventData), "interruptEvents");
362
- addInterruptEvent({
397
+ const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
398
+ localInterrupt = {
363
399
  eventId,
364
400
  threadId,
365
401
  event: eventData
366
- });
402
+ };
403
+ }
404
+ },
405
+ onRunStartedEvent: () => {
406
+ localInterrupt = null;
407
+ },
408
+ onRunFinalized: () => {
409
+ if (localInterrupt) {
410
+ addInterruptEvent(localInterrupt);
411
+ localInterrupt = null;
367
412
  }
368
413
  }
369
414
  };
@@ -372,7 +417,7 @@ function useLangGraphInterruptRender(agent) {
372
417
  unsubscribe();
373
418
  };
374
419
  }, [agent, threadId]);
375
- const handleResolve = (0, import_react5.useCallback)(
420
+ const handleResolve = (0, import_react7.useCallback)(
376
421
  (eventId, response) => {
377
422
  agent == null ? void 0 : agent.runAgent({
378
423
  forwardedProps: {
@@ -381,15 +426,15 @@ function useLangGraphInterruptRender(agent) {
381
426
  }
382
427
  }
383
428
  });
384
- removeInterruptEvent(threadId, eventId);
429
+ resolveInterruptEvent(threadId, eventId, response != null ? response : "");
385
430
  },
386
431
  // eslint-disable-next-line react-hooks/exhaustive-deps
387
432
  [agent, threadId]
388
433
  );
389
- return (0, import_react5.useMemo)(() => {
434
+ return (0, import_react7.useMemo)(() => {
390
435
  const eventQueue = interruptEventQueue[threadId] || [];
391
436
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
392
- if (!currentQueuedEvent)
437
+ if (!currentQueuedEvent || !agentSession)
393
438
  return null;
394
439
  const allActions = Object.values(interruptActions);
395
440
  const matchingAction = allActions.find((action) => {
@@ -397,7 +442,9 @@ function useLangGraphInterruptRender(agent) {
397
442
  return true;
398
443
  return action.enabled({
399
444
  eventValue: currentQueuedEvent.event.value,
400
- agentMetadata: agentSession
445
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
446
+ nodeName
447
+ })
401
448
  });
402
449
  });
403
450
  if (!matchingAction)
@@ -415,7 +462,7 @@ function useLangGraphInterruptRender(agent) {
415
462
  }
416
463
  if (!render)
417
464
  return null;
418
- return import_react5.default.createElement(InterruptRenderer, {
465
+ return import_react7.default.createElement(InterruptRenderer, {
419
466
  event: currentQueuedEvent.event,
420
467
  result,
421
468
  render,
@@ -425,14 +472,14 @@ function useLangGraphInterruptRender(agent) {
425
472
  }
426
473
 
427
474
  // src/hooks/use-copilot-chat_internal.ts
428
- var import_react13 = require("@copilotkitnext/react");
475
+ var import_react14 = require("@copilotkitnext/react");
429
476
 
430
477
  // src/hooks/use-lazy-tool-renderer.tsx
431
- var import_react6 = require("@copilotkitnext/react");
432
- var import_react7 = require("react");
478
+ var import_react9 = require("@copilotkitnext/react");
479
+ var import_react10 = require("react");
433
480
  function useLazyToolRenderer() {
434
- const renderToolCall = (0, import_react6.useRenderToolCall)();
435
- return (0, import_react7.useCallback)(
481
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
482
+ return (0, import_react10.useCallback)(
436
483
  (message, messages) => {
437
484
  var _a;
438
485
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -452,39 +499,7 @@ function useLazyToolRenderer() {
452
499
  );
453
500
  }
454
501
 
455
- // src/hooks/use-configure-chat-suggestions.tsx
456
- var import_react8 = require("@copilotkitnext/react");
457
- var import_react9 = require("react");
458
- function useConfigureChatSuggestions(config, dependencies = []) {
459
- const { agentSession } = useCopilotContext();
460
- const { copilotkit } = (0, import_react8.useCopilotKit)();
461
- const available = config.available === "enabled" ? "always" : config.available;
462
- const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
463
- available,
464
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
465
- // Use chatConfig.agentId here
466
- });
467
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
468
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
469
- (0, import_react9.useEffect)(() => {
470
- if (finalSuggestionConfig.available === "disabled")
471
- return;
472
- const subscription = copilotkit.subscribe({
473
- onAgentsChanged: () => {
474
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
475
- if (agent && !agent.isRunning && !result.suggestions.length) {
476
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
477
- }
478
- }
479
- });
480
- return () => {
481
- subscription.unsubscribe();
482
- };
483
- }, []);
484
- return result;
485
- }
486
-
487
- // ../../node_modules/.pnpm/@ag-ui+core@0.0.42-alpha.1/node_modules/@ag-ui/core/dist/index.mjs
502
+ // ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
488
503
  var import_zod = require("zod");
489
504
  var import_zod2 = require("zod");
490
505
  var FunctionCallSchema = import_zod.z.object({
@@ -890,10 +905,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
890
905
  ]);
891
906
 
892
907
  // src/hooks/use-coagent-state-render-bridge.tsx
893
- var import_react10 = require("@copilotkitnext/react");
894
- var import_react11 = require("react");
908
+ var import_react11 = require("@copilotkitnext/react");
909
+ var import_react12 = require("react");
895
910
  var import_shared3 = require("@copilotkit/shared");
896
911
  function getStateWithoutConstantKeys(state) {
912
+ if (!state)
913
+ return {};
897
914
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
898
915
  return stateWithoutConstantKeys;
899
916
  }
@@ -916,11 +933,11 @@ function useCoagentStateRenderBridge(agentId, props) {
916
933
  var _a;
917
934
  const { stateSnapshot, messageIndexInRun, message } = props;
918
935
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
919
- const { agent } = (0, import_react10.useAgent)({ agentId });
920
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
936
+ const { agent } = (0, import_react11.useAgent)({ agentId });
937
+ const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
921
938
  const runId = (_a = props.runId) != null ? _a : message.runId;
922
939
  const effectiveRunId = runId || "pending";
923
- (0, import_react11.useEffect)(() => {
940
+ (0, import_react12.useEffect)(() => {
924
941
  if (!agent)
925
942
  return;
926
943
  const subscriber = {
@@ -940,10 +957,7 @@ function useCoagentStateRenderBridge(agentId, props) {
940
957
  unsubscribe();
941
958
  };
942
959
  }, [agentId, nodeName]);
943
- if (messageIndexInRun !== 0) {
944
- return null;
945
- }
946
- const getStateRender = (0, import_react11.useCallback)(
960
+ const getStateRender = (0, import_react12.useCallback)(
947
961
  (messageId) => {
948
962
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
949
963
  if (claimsRef.current[messageId]) {
@@ -970,7 +984,7 @@ function useCoagentStateRenderBridge(agentId, props) {
970
984
  return canRender;
971
985
  }
972
986
  const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
973
- (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared3.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
987
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
974
988
  );
975
989
  if (renderClaimedByOtherMessage) {
976
990
  if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
@@ -985,8 +999,11 @@ function useCoagentStateRenderBridge(agentId, props) {
985
999
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
986
1000
  return true;
987
1001
  };
988
- return (0, import_react11.useMemo)(() => {
1002
+ return (0, import_react12.useMemo)(() => {
989
1003
  var _a2, _b, _c;
1004
+ if (messageIndexInRun !== 0) {
1005
+ return null;
1006
+ }
990
1007
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
991
1008
  if (!stateRender || !stateRenderId) {
992
1009
  return null;
@@ -1033,7 +1050,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1033
1050
  agent == null ? void 0 : agent.isRunning,
1034
1051
  nodeName,
1035
1052
  effectiveRunId,
1036
- message.id
1053
+ message.id,
1054
+ messageIndexInRun
1037
1055
  ]);
1038
1056
  }
1039
1057
  function CoAgentStateRenderBridge(props) {
@@ -1041,35 +1059,17 @@ function CoAgentStateRenderBridge(props) {
1041
1059
  }
1042
1060
 
1043
1061
  // src/hooks/use-copilot-chat_internal.ts
1044
- function useConfigureSuggestions2(suggestions) {
1045
- let suggestionsConfig;
1046
- if (Array.isArray(suggestions)) {
1047
- suggestionsConfig = {
1048
- suggestions,
1049
- available: "always"
1050
- };
1051
- } else if (suggestions === "auto") {
1052
- suggestionsConfig = {
1053
- available: suggestions === "auto" ? "always" : "disabled",
1054
- instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
1055
- };
1056
- } else {
1057
- suggestionsConfig = { available: "disabled" };
1058
- }
1059
- useConfigureChatSuggestions(suggestionsConfig);
1060
- }
1061
1062
  function useCopilotChatInternal({
1062
1063
  suggestions
1063
1064
  } = {}) {
1064
- var _a, _b, _c, _d;
1065
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1065
+ var _a, _b, _c;
1066
+ const { copilotkit } = (0, import_react14.useCopilotKit)();
1066
1067
  const { threadId, agentSession } = useCopilotContext();
1067
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1068
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1069
- useConfigureSuggestions2(suggestions);
1070
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1071
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1072
- (0, import_react12.useEffect)(() => {
1068
+ const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
1069
+ const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
1070
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1071
+ const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
1072
+ (0, import_react13.useEffect)(() => {
1073
1073
  const connect = (agent2) => __async(this, null, function* () {
1074
1074
  setAgentAvailable(false);
1075
1075
  try {
@@ -1094,7 +1094,7 @@ function useCopilotChatInternal({
1094
1094
  agent == null ? void 0 : agent.setMessages([]);
1095
1095
  agent == null ? void 0 : agent.setState(null);
1096
1096
  };
1097
- const deleteMessage = (0, import_react12.useCallback)(
1097
+ const deleteMessage = (0, import_react13.useCallback)(
1098
1098
  (messageId) => {
1099
1099
  var _a2;
1100
1100
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1105,13 +1105,13 @@ function useCopilotChatInternal({
1105
1105
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1106
1106
  );
1107
1107
  const latestDelete = useUpdatedRef(deleteMessage);
1108
- const latestDeleteFunc = (0, import_react12.useCallback)(
1108
+ const latestDeleteFunc = (0, import_react13.useCallback)(
1109
1109
  (messageId) => {
1110
1110
  return latestDelete.current(messageId);
1111
1111
  },
1112
1112
  [latestDelete]
1113
1113
  );
1114
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1114
+ const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
1115
1115
  const reload = useAsyncCallback(
1116
1116
  (reloadMessageId) => __async(this, null, function* () {
1117
1117
  var _a2;
@@ -1178,16 +1178,15 @@ function useCopilotChatInternal({
1178
1178
  }),
1179
1179
  [latestSendMessageFunc]
1180
1180
  );
1181
- const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1182
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1181
+ const latestSetMessagesFunc = (0, import_react13.useCallback)(
1183
1182
  (messages) => {
1184
1183
  var _a2, _b2;
1185
1184
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
1186
- return (_a2 = latestSetMessages.current) == null ? void 0 : _a2.call(latestSetMessages, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
1185
+ return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
1187
1186
  }
1188
- return (_b2 = latestSetMessages.current) == null ? void 0 : _b2.call(latestSetMessages, messages);
1187
+ return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
1189
1188
  },
1190
- [latestSetMessages, agent]
1189
+ [agent == null ? void 0 : agent.setMessages, agent]
1191
1190
  );
1192
1191
  const latestReload = useUpdatedRef(reload);
1193
1192
  const latestReloadFunc = useAsyncCallback(
@@ -1196,25 +1195,24 @@ function useCopilotChatInternal({
1196
1195
  }),
1197
1196
  [latestReload]
1198
1197
  );
1199
- const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1200
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1198
+ const latestStopFunc = (0, import_react13.useCallback)(() => {
1201
1199
  var _a2;
1202
- return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1203
- }, [latestStop]);
1200
+ return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
1201
+ }, [agent == null ? void 0 : agent.abortRun]);
1204
1202
  const latestReset = useUpdatedRef(reset);
1205
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1203
+ const latestResetFunc = (0, import_react13.useCallback)(() => {
1206
1204
  return latestReset.current();
1207
1205
  }, [latestReset]);
1208
1206
  const lazyToolRendered = useLazyToolRenderer();
1209
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1207
+ const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
1210
1208
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1211
1209
  copilotkit,
1212
1210
  agent,
1213
1211
  agentId: resolvedAgentId,
1214
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1212
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1215
1213
  });
1216
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1217
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1214
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1215
+ const resolvedMessages = (0, import_react13.useMemo)(() => {
1218
1216
  let processedMessages = allMessages.map((message) => {
1219
1217
  if (message.role !== "assistant") {
1220
1218
  return message;
@@ -1242,33 +1240,24 @@ function useCopilotChatInternal({
1242
1240
  return message;
1243
1241
  });
1244
1242
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1245
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1246
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1247
- const placeholderMessage = {
1248
- id: placeholderId,
1249
- role: "assistant",
1250
- content: "",
1251
- name: "coagent-state-render"
1252
- };
1253
- processedMessages = [
1254
- ...processedMessages,
1255
- __spreadProps(__spreadValues({}, placeholderMessage), {
1256
- generativeUI: () => legacyCustomMessageRenderer({
1257
- message: placeholderMessage,
1258
- position: "before"
1259
- })
1260
- })
1261
- ];
1262
- }
1263
1243
  return processedMessages;
1264
1244
  }, [
1265
1245
  agent == null ? void 0 : agent.messages,
1266
1246
  lazyToolRendered,
1267
1247
  allMessages,
1268
1248
  renderCustomMessage,
1269
- legacyCustomMessageRenderer,
1249
+ // legacyCustomMessageRenderer,
1270
1250
  resolvedAgentId
1271
1251
  ]);
1252
+ const renderedSuggestions = (0, import_react13.useMemo)(() => {
1253
+ if (Array.isArray(suggestions)) {
1254
+ return {
1255
+ suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
1256
+ isLoading: false
1257
+ };
1258
+ }
1259
+ return currentSuggestions;
1260
+ }, [suggestions, currentSuggestions]);
1272
1261
  return {
1273
1262
  messages: resolvedMessages,
1274
1263
  sendMessage: latestSendMessageFunc,
@@ -1278,25 +1267,25 @@ function useCopilotChatInternal({
1278
1267
  stopGeneration: latestStopFunc,
1279
1268
  reset: latestResetFunc,
1280
1269
  deleteMessage: latestDeleteFunc,
1281
- isAvailable: !agentAvailable,
1270
+ isAvailable: agentAvailable,
1282
1271
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1283
1272
  // mcpServers,
1284
1273
  // setMcpServers,
1285
- suggestions: currentSuggestions.suggestions,
1274
+ suggestions: renderedSuggestions.suggestions,
1286
1275
  setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
1287
1276
  generateSuggestions: () => __async(this, null, function* () {
1288
1277
  return copilotkit.reloadSuggestions(resolvedAgentId);
1289
1278
  }),
1290
1279
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
1291
- isLoadingSuggestions: currentSuggestions.isLoading,
1280
+ isLoadingSuggestions: renderedSuggestions.isLoading,
1292
1281
  interrupt,
1293
1282
  agent,
1294
1283
  threadId
1295
1284
  };
1296
1285
  }
1297
1286
  function useUpdatedRef(value) {
1298
- const ref = (0, import_react12.useRef)(value);
1299
- (0, import_react12.useEffect)(() => {
1287
+ const ref = (0, import_react13.useRef)(value);
1288
+ (0, import_react13.useEffect)(() => {
1300
1289
  ref.current = value;
1301
1290
  }, [value]);
1302
1291
  return ref;
@@ -1307,20 +1296,19 @@ function useLegacyCoagentRenderer({
1307
1296
  agentId,
1308
1297
  threadId
1309
1298
  }) {
1310
- return (0, import_react12.useMemo)(() => {
1299
+ return (0, import_react13.useMemo)(() => {
1311
1300
  if (!copilotkit || !agent) {
1312
1301
  return null;
1313
1302
  }
1314
1303
  return ({ message, position }) => {
1315
1304
  var _a;
1316
1305
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1317
- const existingRunId = copilotkit.getRunIdForMessage(
1318
- agentId,
1319
- effectiveThreadId,
1320
- message.id
1321
- );
1306
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1322
1307
  const runId = existingRunId || `pending:${message.id}`;
1323
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1308
+ const messageIndex = Math.max(
1309
+ agent.messages.findIndex((msg) => msg.id === message.id),
1310
+ 0
1311
+ );
1324
1312
  const bridgeProps = {
1325
1313
  message,
1326
1314
  position,
@@ -1331,7 +1319,7 @@ function useLegacyCoagentRenderer({
1331
1319
  agentId,
1332
1320
  stateSnapshot: message.state
1333
1321
  };
1334
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1322
+ return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
1335
1323
  };
1336
1324
  }, [agent, agentId, copilotkit, threadId]);
1337
1325
  }