@copilotkit/react-core 1.50.0-beta.1 → 1.50.0-beta.2

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 (141) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{chunk-IUSKVYUI.mjs → chunk-2CYJN455.mjs} +2 -1
  3. package/dist/{chunk-IUSKVYUI.mjs.map → chunk-2CYJN455.mjs.map} +1 -1
  4. package/dist/{chunk-UJBV5GAG.mjs → chunk-6F7Q6CPI.mjs} +17 -36
  5. package/dist/chunk-6F7Q6CPI.mjs.map +1 -0
  6. package/dist/{chunk-JRT5BJF3.mjs → chunk-6SK26J65.mjs} +2 -2
  7. package/dist/{chunk-3GURHDG7.mjs → chunk-BPJ6V4YX.mjs} +2 -2
  8. package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
  9. package/dist/{chunk-3R423LZT.mjs → chunk-EHXVGFWN.mjs} +2 -2
  10. package/dist/{chunk-CB7CRBDG.mjs → chunk-FBVI3LQ6.mjs} +11 -11
  11. package/dist/chunk-FBVI3LQ6.mjs.map +1 -0
  12. package/dist/chunk-I76HKHPJ.mjs +32 -0
  13. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  14. package/dist/{chunk-R4MR43UQ.mjs → chunk-ISNVEPPQ.mjs} +17 -3
  15. package/dist/chunk-ISNVEPPQ.mjs.map +1 -0
  16. package/dist/{chunk-FBD24VEH.mjs → chunk-LD3MGPZB.mjs} +1 -1
  17. package/dist/{chunk-FBD24VEH.mjs.map → chunk-LD3MGPZB.mjs.map} +1 -1
  18. package/dist/{chunk-GMI4KO4X.mjs → chunk-OAEX7G5G.mjs} +2 -2
  19. package/dist/{chunk-DCHSCK62.mjs → chunk-SD7TUPQM.mjs} +13 -14
  20. package/dist/chunk-SD7TUPQM.mjs.map +1 -0
  21. package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
  22. package/dist/chunk-T2VBHAAP.mjs.map +1 -0
  23. package/dist/{chunk-NROJOTQP.mjs → chunk-TGIWTM6S.mjs} +8 -5
  24. package/dist/chunk-TGIWTM6S.mjs.map +1 -0
  25. package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
  26. package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
  27. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  28. package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
  29. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  30. package/dist/components/CopilotListeners.js +13 -146
  31. package/dist/components/CopilotListeners.js.map +1 -1
  32. package/dist/components/CopilotListeners.mjs +1 -6
  33. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  34. package/dist/components/copilot-provider/copilot-messages.mjs +1 -1
  35. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  36. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  37. package/dist/components/copilot-provider/copilotkit.js +11 -11
  38. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  39. package/dist/components/copilot-provider/copilotkit.mjs +6 -6
  40. package/dist/components/copilot-provider/index.d.ts +1 -1
  41. package/dist/components/copilot-provider/index.js +11 -11
  42. package/dist/components/copilot-provider/index.js.map +1 -1
  43. package/dist/components/copilot-provider/index.mjs +6 -6
  44. package/dist/components/index.d.ts +1 -1
  45. package/dist/components/index.js +11 -11
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/index.mjs +6 -6
  48. package/dist/context/copilot-context.d.ts +1 -1
  49. package/dist/context/index.d.ts +1 -1
  50. package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-81022020.d.ts} +1 -1
  51. package/dist/hooks/index.d.ts +1 -1
  52. package/dist/hooks/index.js +187 -155
  53. package/dist/hooks/index.js.map +1 -1
  54. package/dist/hooks/index.mjs +24 -23
  55. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  56. package/dist/hooks/use-agent-nodename.js +56 -0
  57. package/dist/hooks/use-agent-nodename.js.map +1 -0
  58. package/dist/hooks/use-agent-nodename.mjs +8 -0
  59. package/dist/hooks/use-agent-nodename.mjs.map +1 -0
  60. package/dist/hooks/use-coagent-state-render-bridge.js +7 -4
  61. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
  62. package/dist/hooks/use-coagent-state-render-bridge.mjs +1 -1
  63. package/dist/hooks/use-coagent.js +58 -21
  64. package/dist/hooks/use-coagent.js.map +1 -1
  65. package/dist/hooks/use-coagent.mjs +2 -1
  66. package/dist/hooks/use-configure-chat-suggestions.js +13 -144
  67. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -1
  68. package/dist/hooks/use-configure-chat-suggestions.mjs +1 -6
  69. package/dist/hooks/use-copilot-action.js +5 -1
  70. package/dist/hooks/use-copilot-action.js.map +1 -1
  71. package/dist/hooks/use-copilot-action.mjs +2 -2
  72. package/dist/hooks/use-copilot-authenticated-action.js +5 -1
  73. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  74. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  75. package/dist/hooks/use-copilot-chat-headless_c.js +107 -84
  76. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  77. package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -5
  78. package/dist/hooks/use-copilot-chat.js +105 -82
  79. package/dist/hooks/use-copilot-chat.js.map +1 -1
  80. package/dist/hooks/use-copilot-chat.mjs +6 -5
  81. package/dist/hooks/use-copilot-chat_internal.d.ts +1 -1
  82. package/dist/hooks/use-copilot-chat_internal.js +105 -82
  83. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  84. package/dist/hooks/use-copilot-chat_internal.mjs +5 -4
  85. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  86. package/dist/hooks/use-copilot-readable.js +1 -0
  87. package/dist/hooks/use-copilot-readable.js.map +1 -1
  88. package/dist/hooks/use-copilot-readable.mjs +1 -1
  89. package/dist/hooks/use-default-tool.js +5 -1
  90. package/dist/hooks/use-default-tool.js.map +1 -1
  91. package/dist/hooks/use-default-tool.mjs +3 -3
  92. package/dist/hooks/use-frontend-tool.js +5 -1
  93. package/dist/hooks/use-frontend-tool.js.map +1 -1
  94. package/dist/hooks/use-frontend-tool.mjs +1 -1
  95. package/dist/hooks/use-langgraph-interrupt-render.js +61 -7
  96. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  97. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -1
  98. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  99. package/dist/index.d.ts +1 -1
  100. package/dist/index.js +184 -155
  101. package/dist/index.js.map +1 -1
  102. package/dist/index.mjs +31 -30
  103. package/dist/lib/copilot-task.d.ts +1 -1
  104. package/dist/lib/copilot-task.js.map +1 -1
  105. package/dist/lib/copilot-task.mjs +7 -7
  106. package/dist/lib/index.d.ts +1 -1
  107. package/dist/lib/index.js.map +1 -1
  108. package/dist/lib/index.mjs +7 -7
  109. package/dist/types/index.d.ts +1 -1
  110. package/dist/types/index.mjs +1 -1
  111. package/dist/types/interrupt-action.d.ts +1 -1
  112. package/dist/types/interrupt-action.js.map +1 -1
  113. package/jest.config.js +12 -0
  114. package/package.json +7 -6
  115. package/src/components/CopilotListeners.tsx +1 -2
  116. package/src/components/copilot-provider/copilot-messages.tsx +0 -41
  117. package/src/components/copilot-provider/copilotkit.tsx +2 -2
  118. package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
  119. package/src/hooks/use-agent-nodename.ts +30 -0
  120. package/src/hooks/use-coagent-state-render-bridge.tsx +20 -20
  121. package/src/hooks/use-coagent.ts +22 -13
  122. package/src/hooks/use-configure-chat-suggestions.tsx +8 -7
  123. package/src/hooks/use-copilot-chat_internal.ts +44 -42
  124. package/src/hooks/use-copilot-readable.ts +2 -1
  125. package/src/hooks/use-frontend-tool.ts +10 -2
  126. package/src/hooks/use-langgraph-interrupt-render.ts +10 -2
  127. package/src/types/interrupt-action.ts +1 -1
  128. package/dist/chunk-24SCZAB4.mjs.map +0 -1
  129. package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
  130. package/dist/chunk-CB7CRBDG.mjs.map +0 -1
  131. package/dist/chunk-DCHSCK62.mjs.map +0 -1
  132. package/dist/chunk-NG26QEGF.mjs.map +0 -1
  133. package/dist/chunk-NROJOTQP.mjs.map +0 -1
  134. package/dist/chunk-R4MR43UQ.mjs.map +0 -1
  135. package/dist/chunk-UJBV5GAG.mjs.map +0 -1
  136. /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-6SK26J65.mjs.map} +0 -0
  137. /package/dist/{chunk-3GURHDG7.mjs.map → chunk-BPJ6V4YX.mjs.map} +0 -0
  138. /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
  139. /package/dist/{chunk-3R423LZT.mjs.map → chunk-EHXVGFWN.mjs.map} +0 -0
  140. /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-OAEX7G5G.mjs.map} +0 -0
  141. /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  useCopilotChatHeadless_c
3
- } from "../chunk-3R423LZT.mjs";
3
+ } from "../chunk-EHXVGFWN.mjs";
4
4
  import {
5
5
  defaultSystemMessage
6
- } from "../chunk-UJBV5GAG.mjs";
6
+ } from "../chunk-6F7Q6CPI.mjs";
7
+ import "../chunk-ISNVEPPQ.mjs";
7
8
  import "../chunk-ZVF5Q6IH.mjs";
8
- import "../chunk-R4MR43UQ.mjs";
9
- import "../chunk-CB7CRBDG.mjs";
9
+ import "../chunk-I76HKHPJ.mjs";
10
+ import "../chunk-FBVI3LQ6.mjs";
10
11
  import "../chunk-6PUNP7CD.mjs";
11
12
  import "../chunk-O7ARI5CV.mjs";
12
- import "../chunk-NROJOTQP.mjs";
13
+ import "../chunk-TGIWTM6S.mjs";
13
14
  import "../chunk-NB2FKV2V.mjs";
14
15
  import "../chunk-F555TVE4.mjs";
15
16
  import "../chunk-EFL5OBKN.mjs";
@@ -84,7 +84,7 @@ __export(use_copilot_chat_exports, {
84
84
  module.exports = __toCommonJS(use_copilot_chat_exports);
85
85
 
86
86
  // src/hooks/use-copilot-chat_internal.ts
87
- var import_react12 = require("react");
87
+ var import_react15 = require("react");
88
88
 
89
89
  // src/context/copilot-context.tsx
90
90
  var import_react = __toESM(require("react"));
@@ -333,13 +333,45 @@ function useCoAgentStateRenders() {
333
333
  }
334
334
 
335
335
  // src/hooks/use-langgraph-interrupt-render.ts
336
- var import_react5 = __toESM(require("react"));
336
+ var import_react7 = __toESM(require("react"));
337
337
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
338
338
  var import_shared2 = require("@copilotkit/shared");
339
+
340
+ // src/hooks/use-agent-nodename.ts
341
+ var import_react5 = require("react");
342
+ var import_react6 = require("@copilotkitnext/react");
343
+ function useAgentNodeName(agentName) {
344
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
345
+ const nodeNameRef = (0, import_react5.useRef)("start");
346
+ (0, import_react5.useEffect)(() => {
347
+ if (!agent)
348
+ return;
349
+ const subscriber = {
350
+ onStepStartedEvent: ({ event }) => {
351
+ nodeNameRef.current = event.stepName;
352
+ },
353
+ onRunStartedEvent: () => {
354
+ nodeNameRef.current = "start";
355
+ },
356
+ onRunFinishedEvent: () => {
357
+ nodeNameRef.current = "end";
358
+ }
359
+ };
360
+ const subscription = agent.subscribe(subscriber);
361
+ return () => {
362
+ subscription.unsubscribe();
363
+ };
364
+ }, [agent]);
365
+ return nodeNameRef.current;
366
+ }
367
+
368
+ // src/hooks/use-langgraph-interrupt-render.ts
369
+ var import_react8 = require("@copilotkitnext/react");
339
370
  var InterruptRenderer = ({ event, result, render, resolve }) => {
340
371
  return render({ event, result, resolve });
341
372
  };
342
373
  function useLangGraphInterruptRender(agent) {
374
+ var _a;
343
375
  const {
344
376
  interruptActions,
345
377
  agentSession,
@@ -348,7 +380,10 @@ function useLangGraphInterruptRender(agent) {
348
380
  addInterruptEvent,
349
381
  removeInterruptEvent
350
382
  } = useCopilotContext();
351
- (0, import_react5.useEffect)(() => {
383
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
384
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
385
+ const nodeName = useAgentNodeName(resolvedAgentId);
386
+ (0, import_react7.useEffect)(() => {
352
387
  if (!agent)
353
388
  return;
354
389
  const subscriber = {
@@ -373,7 +408,7 @@ function useLangGraphInterruptRender(agent) {
373
408
  unsubscribe();
374
409
  };
375
410
  }, [agent, threadId]);
376
- const handleResolve = (0, import_react5.useCallback)(
411
+ const handleResolve = (0, import_react7.useCallback)(
377
412
  (eventId, response) => {
378
413
  agent == null ? void 0 : agent.runAgent({
379
414
  forwardedProps: {
@@ -387,10 +422,10 @@ function useLangGraphInterruptRender(agent) {
387
422
  // eslint-disable-next-line react-hooks/exhaustive-deps
388
423
  [agent, threadId]
389
424
  );
390
- return (0, import_react5.useMemo)(() => {
425
+ return (0, import_react7.useMemo)(() => {
391
426
  const eventQueue = interruptEventQueue[threadId] || [];
392
427
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
393
- if (!currentQueuedEvent)
428
+ if (!currentQueuedEvent || !agentSession)
394
429
  return null;
395
430
  const allActions = Object.values(interruptActions);
396
431
  const matchingAction = allActions.find((action) => {
@@ -398,7 +433,9 @@ function useLangGraphInterruptRender(agent) {
398
433
  return true;
399
434
  return action.enabled({
400
435
  eventValue: currentQueuedEvent.event.value,
401
- agentMetadata: agentSession
436
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
437
+ nodeName
438
+ })
402
439
  });
403
440
  });
404
441
  if (!matchingAction)
@@ -416,7 +453,7 @@ function useLangGraphInterruptRender(agent) {
416
453
  }
417
454
  if (!render)
418
455
  return null;
419
- return import_react5.default.createElement(InterruptRenderer, {
456
+ return import_react7.default.createElement(InterruptRenderer, {
420
457
  event: currentQueuedEvent.event,
421
458
  result,
422
459
  render,
@@ -426,14 +463,14 @@ function useLangGraphInterruptRender(agent) {
426
463
  }
427
464
 
428
465
  // src/hooks/use-copilot-chat_internal.ts
429
- var import_react13 = require("@copilotkitnext/react");
466
+ var import_react16 = require("@copilotkitnext/react");
430
467
 
431
468
  // src/hooks/use-lazy-tool-renderer.tsx
432
- var import_react6 = require("@copilotkitnext/react");
433
- var import_react7 = require("react");
469
+ var import_react9 = require("@copilotkitnext/react");
470
+ var import_react10 = require("react");
434
471
  function useLazyToolRenderer() {
435
- const renderToolCall = (0, import_react6.useRenderToolCall)();
436
- return (0, import_react7.useCallback)(
472
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
473
+ return (0, import_react10.useCallback)(
437
474
  (message, messages) => {
438
475
  var _a;
439
476
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -454,34 +491,36 @@ function useLazyToolRenderer() {
454
491
  }
455
492
 
456
493
  // src/hooks/use-configure-chat-suggestions.tsx
457
- var import_react8 = require("@copilotkitnext/react");
458
- var import_react9 = require("react");
494
+ var import_react11 = require("@copilotkitnext/react");
495
+ var import_react12 = require("react");
459
496
  function useConfigureChatSuggestions(config, dependencies = []) {
460
- const { agentSession } = useCopilotContext();
461
- const { copilotkit } = (0, import_react8.useCopilotKit)();
497
+ var _a;
498
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
499
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
500
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
462
501
  const available = config.available === "enabled" ? "always" : config.available;
463
502
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
464
503
  available,
465
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
504
+ consumerAgentId: resolvedAgentId
466
505
  // Use chatConfig.agentId here
467
506
  });
468
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
469
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
470
- (0, import_react9.useEffect)(() => {
507
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
508
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
509
+ (0, import_react12.useEffect)(() => {
471
510
  if (finalSuggestionConfig.available === "disabled")
472
511
  return;
473
512
  const subscription = copilotkit.subscribe({
474
513
  onAgentsChanged: () => {
475
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
514
+ const agent = copilotkit.getAgent(resolvedAgentId);
476
515
  if (agent && !agent.isRunning && !result.suggestions.length) {
477
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
516
+ copilotkit.reloadSuggestions(resolvedAgentId);
478
517
  }
479
518
  }
480
519
  });
481
520
  return () => {
482
521
  subscription.unsubscribe();
483
522
  };
484
- }, []);
523
+ }, [resolvedAgentId]);
485
524
  return result;
486
525
  }
487
526
 
@@ -891,10 +930,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
891
930
  ]);
892
931
 
893
932
  // src/hooks/use-coagent-state-render-bridge.tsx
894
- var import_react10 = require("@copilotkitnext/react");
895
- var import_react11 = require("react");
933
+ var import_react13 = require("@copilotkitnext/react");
934
+ var import_react14 = require("react");
896
935
  var import_shared3 = require("@copilotkit/shared");
897
936
  function getStateWithoutConstantKeys(state) {
937
+ if (!state)
938
+ return {};
898
939
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
899
940
  return stateWithoutConstantKeys;
900
941
  }
@@ -917,11 +958,11 @@ function useCoagentStateRenderBridge(agentId, props) {
917
958
  var _a;
918
959
  const { stateSnapshot, messageIndexInRun, message } = props;
919
960
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
920
- const { agent } = (0, import_react10.useAgent)({ agentId });
921
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
961
+ const { agent } = (0, import_react13.useAgent)({ agentId });
962
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
922
963
  const runId = (_a = props.runId) != null ? _a : message.runId;
923
964
  const effectiveRunId = runId || "pending";
924
- (0, import_react11.useEffect)(() => {
965
+ (0, import_react14.useEffect)(() => {
925
966
  if (!agent)
926
967
  return;
927
968
  const subscriber = {
@@ -941,10 +982,7 @@ function useCoagentStateRenderBridge(agentId, props) {
941
982
  unsubscribe();
942
983
  };
943
984
  }, [agentId, nodeName]);
944
- if (messageIndexInRun !== 0) {
945
- return null;
946
- }
947
- const getStateRender = (0, import_react11.useCallback)(
985
+ const getStateRender = (0, import_react14.useCallback)(
948
986
  (messageId) => {
949
987
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
950
988
  if (claimsRef.current[messageId]) {
@@ -986,8 +1024,11 @@ function useCoagentStateRenderBridge(agentId, props) {
986
1024
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
987
1025
  return true;
988
1026
  };
989
- return (0, import_react11.useMemo)(() => {
1027
+ return (0, import_react14.useMemo)(() => {
990
1028
  var _a2, _b, _c;
1029
+ if (messageIndexInRun !== 0) {
1030
+ return null;
1031
+ }
991
1032
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
992
1033
  if (!stateRender || !stateRenderId) {
993
1034
  return null;
@@ -1034,7 +1075,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1034
1075
  agent == null ? void 0 : agent.isRunning,
1035
1076
  nodeName,
1036
1077
  effectiveRunId,
1037
- message.id
1078
+ message.id,
1079
+ messageIndexInRun
1038
1080
  ]);
1039
1081
  }
1040
1082
  function CoAgentStateRenderBridge(props) {
@@ -1062,15 +1104,15 @@ function useConfigureSuggestions2(suggestions) {
1062
1104
  function useCopilotChatInternal({
1063
1105
  suggestions
1064
1106
  } = {}) {
1065
- var _a, _b, _c, _d;
1066
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1107
+ var _a, _b, _c;
1108
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1067
1109
  const { threadId, agentSession } = useCopilotContext();
1068
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1069
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1110
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1111
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1070
1112
  useConfigureSuggestions2(suggestions);
1071
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1072
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1073
- (0, import_react12.useEffect)(() => {
1113
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1114
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1115
+ (0, import_react15.useEffect)(() => {
1074
1116
  const connect = (agent2) => __async(this, null, function* () {
1075
1117
  setAgentAvailable(false);
1076
1118
  try {
@@ -1095,7 +1137,7 @@ function useCopilotChatInternal({
1095
1137
  agent == null ? void 0 : agent.setMessages([]);
1096
1138
  agent == null ? void 0 : agent.setState(null);
1097
1139
  };
1098
- const deleteMessage = (0, import_react12.useCallback)(
1140
+ const deleteMessage = (0, import_react15.useCallback)(
1099
1141
  (messageId) => {
1100
1142
  var _a2;
1101
1143
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1106,13 +1148,13 @@ function useCopilotChatInternal({
1106
1148
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1107
1149
  );
1108
1150
  const latestDelete = useUpdatedRef(deleteMessage);
1109
- const latestDeleteFunc = (0, import_react12.useCallback)(
1151
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1110
1152
  (messageId) => {
1111
1153
  return latestDelete.current(messageId);
1112
1154
  },
1113
1155
  [latestDelete]
1114
1156
  );
1115
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1157
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1116
1158
  const reload = useAsyncCallback(
1117
1159
  (reloadMessageId) => __async(this, null, function* () {
1118
1160
  var _a2;
@@ -1180,7 +1222,7 @@ function useCopilotChatInternal({
1180
1222
  [latestSendMessageFunc]
1181
1223
  );
1182
1224
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1183
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1225
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1184
1226
  (messages) => {
1185
1227
  var _a2, _b2;
1186
1228
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1198,24 +1240,24 @@ function useCopilotChatInternal({
1198
1240
  [latestReload]
1199
1241
  );
1200
1242
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1201
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1243
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1202
1244
  var _a2;
1203
1245
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1204
1246
  }, [latestStop]);
1205
1247
  const latestReset = useUpdatedRef(reset);
1206
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1248
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1207
1249
  return latestReset.current();
1208
1250
  }, [latestReset]);
1209
1251
  const lazyToolRendered = useLazyToolRenderer();
1210
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1252
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1211
1253
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1212
1254
  copilotkit,
1213
1255
  agent,
1214
1256
  agentId: resolvedAgentId,
1215
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1257
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1216
1258
  });
1217
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1218
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1259
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1260
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1219
1261
  let processedMessages = allMessages.map((message) => {
1220
1262
  if (message.role !== "assistant") {
1221
1263
  return message;
@@ -1243,31 +1285,13 @@ function useCopilotChatInternal({
1243
1285
  return message;
1244
1286
  });
1245
1287
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1246
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1247
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1248
- const placeholderMessage = {
1249
- id: placeholderId,
1250
- role: "assistant",
1251
- content: "",
1252
- name: "coagent-state-render"
1253
- };
1254
- processedMessages = [
1255
- ...processedMessages,
1256
- __spreadProps(__spreadValues({}, placeholderMessage), {
1257
- generativeUI: () => legacyCustomMessageRenderer({
1258
- message: placeholderMessage,
1259
- position: "before"
1260
- })
1261
- })
1262
- ];
1263
- }
1264
1288
  return processedMessages;
1265
1289
  }, [
1266
1290
  agent == null ? void 0 : agent.messages,
1267
1291
  lazyToolRendered,
1268
1292
  allMessages,
1269
1293
  renderCustomMessage,
1270
- legacyCustomMessageRenderer,
1294
+ // legacyCustomMessageRenderer,
1271
1295
  resolvedAgentId
1272
1296
  ]);
1273
1297
  return {
@@ -1279,7 +1303,7 @@ function useCopilotChatInternal({
1279
1303
  stopGeneration: latestStopFunc,
1280
1304
  reset: latestResetFunc,
1281
1305
  deleteMessage: latestDeleteFunc,
1282
- isAvailable: !agentAvailable,
1306
+ isAvailable: agentAvailable,
1283
1307
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1284
1308
  // mcpServers,
1285
1309
  // setMcpServers,
@@ -1296,8 +1320,8 @@ function useCopilotChatInternal({
1296
1320
  };
1297
1321
  }
1298
1322
  function useUpdatedRef(value) {
1299
- const ref = (0, import_react12.useRef)(value);
1300
- (0, import_react12.useEffect)(() => {
1323
+ const ref = (0, import_react15.useRef)(value);
1324
+ (0, import_react15.useEffect)(() => {
1301
1325
  ref.current = value;
1302
1326
  }, [value]);
1303
1327
  return ref;
@@ -1308,20 +1332,19 @@ function useLegacyCoagentRenderer({
1308
1332
  agentId,
1309
1333
  threadId
1310
1334
  }) {
1311
- return (0, import_react12.useMemo)(() => {
1335
+ return (0, import_react15.useMemo)(() => {
1312
1336
  if (!copilotkit || !agent) {
1313
1337
  return null;
1314
1338
  }
1315
1339
  return ({ message, position }) => {
1316
1340
  var _a;
1317
1341
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1318
- const existingRunId = copilotkit.getRunIdForMessage(
1319
- agentId,
1320
- effectiveThreadId,
1321
- message.id
1322
- );
1342
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1323
1343
  const runId = existingRunId || `pending:${message.id}`;
1324
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1344
+ const messageIndex = Math.max(
1345
+ agent.messages.findIndex((msg) => msg.id === message.id),
1346
+ 0
1347
+ );
1325
1348
  const bridgeProps = {
1326
1349
  message,
1327
1350
  position,
@@ -1332,7 +1355,7 @@ function useLegacyCoagentRenderer({
1332
1355
  agentId,
1333
1356
  stateSnapshot: message.state
1334
1357
  };
1335
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1358
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1336
1359
  };
1337
1360
  }, [agent, agentId, copilotkit, threadId]);
1338
1361
  }