@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
@@ -83,7 +83,7 @@ __export(use_copilot_chat_internal_exports, {
83
83
  useCopilotChatInternal: () => useCopilotChatInternal
84
84
  });
85
85
  module.exports = __toCommonJS(use_copilot_chat_internal_exports);
86
- var import_react12 = require("react");
86
+ var import_react15 = require("react");
87
87
 
88
88
  // src/context/copilot-context.tsx
89
89
  var import_react = __toESM(require("react"));
@@ -332,13 +332,45 @@ 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,
@@ -347,7 +379,10 @@ function useLangGraphInterruptRender(agent) {
347
379
  addInterruptEvent,
348
380
  removeInterruptEvent
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;
353
388
  const subscriber = {
@@ -372,7 +407,7 @@ function useLangGraphInterruptRender(agent) {
372
407
  unsubscribe();
373
408
  };
374
409
  }, [agent, threadId]);
375
- const handleResolve = (0, import_react5.useCallback)(
410
+ const handleResolve = (0, import_react7.useCallback)(
376
411
  (eventId, response) => {
377
412
  agent == null ? void 0 : agent.runAgent({
378
413
  forwardedProps: {
@@ -386,10 +421,10 @@ function useLangGraphInterruptRender(agent) {
386
421
  // eslint-disable-next-line react-hooks/exhaustive-deps
387
422
  [agent, threadId]
388
423
  );
389
- return (0, import_react5.useMemo)(() => {
424
+ return (0, import_react7.useMemo)(() => {
390
425
  const eventQueue = interruptEventQueue[threadId] || [];
391
426
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
392
- if (!currentQueuedEvent)
427
+ if (!currentQueuedEvent || !agentSession)
393
428
  return null;
394
429
  const allActions = Object.values(interruptActions);
395
430
  const matchingAction = allActions.find((action) => {
@@ -397,7 +432,9 @@ function useLangGraphInterruptRender(agent) {
397
432
  return true;
398
433
  return action.enabled({
399
434
  eventValue: currentQueuedEvent.event.value,
400
- agentMetadata: agentSession
435
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
436
+ nodeName
437
+ })
401
438
  });
402
439
  });
403
440
  if (!matchingAction)
@@ -415,7 +452,7 @@ function useLangGraphInterruptRender(agent) {
415
452
  }
416
453
  if (!render)
417
454
  return null;
418
- return import_react5.default.createElement(InterruptRenderer, {
455
+ return import_react7.default.createElement(InterruptRenderer, {
419
456
  event: currentQueuedEvent.event,
420
457
  result,
421
458
  render,
@@ -425,14 +462,14 @@ function useLangGraphInterruptRender(agent) {
425
462
  }
426
463
 
427
464
  // src/hooks/use-copilot-chat_internal.ts
428
- var import_react13 = require("@copilotkitnext/react");
465
+ var import_react16 = require("@copilotkitnext/react");
429
466
 
430
467
  // src/hooks/use-lazy-tool-renderer.tsx
431
- var import_react6 = require("@copilotkitnext/react");
432
- var import_react7 = require("react");
468
+ var import_react9 = require("@copilotkitnext/react");
469
+ var import_react10 = require("react");
433
470
  function useLazyToolRenderer() {
434
- const renderToolCall = (0, import_react6.useRenderToolCall)();
435
- return (0, import_react7.useCallback)(
471
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
472
+ return (0, import_react10.useCallback)(
436
473
  (message, messages) => {
437
474
  var _a;
438
475
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -453,34 +490,36 @@ function useLazyToolRenderer() {
453
490
  }
454
491
 
455
492
  // src/hooks/use-configure-chat-suggestions.tsx
456
- var import_react8 = require("@copilotkitnext/react");
457
- var import_react9 = require("react");
493
+ var import_react11 = require("@copilotkitnext/react");
494
+ var import_react12 = require("react");
458
495
  function useConfigureChatSuggestions(config, dependencies = []) {
459
- const { agentSession } = useCopilotContext();
460
- const { copilotkit } = (0, import_react8.useCopilotKit)();
496
+ var _a;
497
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
498
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
499
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
461
500
  const available = config.available === "enabled" ? "always" : config.available;
462
501
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
463
502
  available,
464
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
503
+ consumerAgentId: resolvedAgentId
465
504
  // Use chatConfig.agentId here
466
505
  });
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)(() => {
506
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
507
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
508
+ (0, import_react12.useEffect)(() => {
470
509
  if (finalSuggestionConfig.available === "disabled")
471
510
  return;
472
511
  const subscription = copilotkit.subscribe({
473
512
  onAgentsChanged: () => {
474
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
513
+ const agent = copilotkit.getAgent(resolvedAgentId);
475
514
  if (agent && !agent.isRunning && !result.suggestions.length) {
476
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
515
+ copilotkit.reloadSuggestions(resolvedAgentId);
477
516
  }
478
517
  }
479
518
  });
480
519
  return () => {
481
520
  subscription.unsubscribe();
482
521
  };
483
- }, []);
522
+ }, [resolvedAgentId]);
484
523
  return result;
485
524
  }
486
525
 
@@ -890,10 +929,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
890
929
  ]);
891
930
 
892
931
  // src/hooks/use-coagent-state-render-bridge.tsx
893
- var import_react10 = require("@copilotkitnext/react");
894
- var import_react11 = require("react");
932
+ var import_react13 = require("@copilotkitnext/react");
933
+ var import_react14 = require("react");
895
934
  var import_shared3 = require("@copilotkit/shared");
896
935
  function getStateWithoutConstantKeys(state) {
936
+ if (!state)
937
+ return {};
897
938
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
898
939
  return stateWithoutConstantKeys;
899
940
  }
@@ -916,11 +957,11 @@ function useCoagentStateRenderBridge(agentId, props) {
916
957
  var _a;
917
958
  const { stateSnapshot, messageIndexInRun, message } = props;
918
959
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
919
- const { agent } = (0, import_react10.useAgent)({ agentId });
920
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
960
+ const { agent } = (0, import_react13.useAgent)({ agentId });
961
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
921
962
  const runId = (_a = props.runId) != null ? _a : message.runId;
922
963
  const effectiveRunId = runId || "pending";
923
- (0, import_react11.useEffect)(() => {
964
+ (0, import_react14.useEffect)(() => {
924
965
  if (!agent)
925
966
  return;
926
967
  const subscriber = {
@@ -940,10 +981,7 @@ function useCoagentStateRenderBridge(agentId, props) {
940
981
  unsubscribe();
941
982
  };
942
983
  }, [agentId, nodeName]);
943
- if (messageIndexInRun !== 0) {
944
- return null;
945
- }
946
- const getStateRender = (0, import_react11.useCallback)(
984
+ const getStateRender = (0, import_react14.useCallback)(
947
985
  (messageId) => {
948
986
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
949
987
  if (claimsRef.current[messageId]) {
@@ -985,8 +1023,11 @@ function useCoagentStateRenderBridge(agentId, props) {
985
1023
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
986
1024
  return true;
987
1025
  };
988
- return (0, import_react11.useMemo)(() => {
1026
+ return (0, import_react14.useMemo)(() => {
989
1027
  var _a2, _b, _c;
1028
+ if (messageIndexInRun !== 0) {
1029
+ return null;
1030
+ }
990
1031
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
991
1032
  if (!stateRender || !stateRenderId) {
992
1033
  return null;
@@ -1033,7 +1074,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1033
1074
  agent == null ? void 0 : agent.isRunning,
1034
1075
  nodeName,
1035
1076
  effectiveRunId,
1036
- message.id
1077
+ message.id,
1078
+ messageIndexInRun
1037
1079
  ]);
1038
1080
  }
1039
1081
  function CoAgentStateRenderBridge(props) {
@@ -1061,15 +1103,15 @@ function useConfigureSuggestions2(suggestions) {
1061
1103
  function useCopilotChatInternal({
1062
1104
  suggestions
1063
1105
  } = {}) {
1064
- var _a, _b, _c, _d;
1065
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1106
+ var _a, _b, _c;
1107
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1066
1108
  const { threadId, agentSession } = useCopilotContext();
1067
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1068
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1109
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1110
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1069
1111
  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)(() => {
1112
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1113
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1114
+ (0, import_react15.useEffect)(() => {
1073
1115
  const connect = (agent2) => __async(this, null, function* () {
1074
1116
  setAgentAvailable(false);
1075
1117
  try {
@@ -1094,7 +1136,7 @@ function useCopilotChatInternal({
1094
1136
  agent == null ? void 0 : agent.setMessages([]);
1095
1137
  agent == null ? void 0 : agent.setState(null);
1096
1138
  };
1097
- const deleteMessage = (0, import_react12.useCallback)(
1139
+ const deleteMessage = (0, import_react15.useCallback)(
1098
1140
  (messageId) => {
1099
1141
  var _a2;
1100
1142
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1105,13 +1147,13 @@ function useCopilotChatInternal({
1105
1147
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1106
1148
  );
1107
1149
  const latestDelete = useUpdatedRef(deleteMessage);
1108
- const latestDeleteFunc = (0, import_react12.useCallback)(
1150
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1109
1151
  (messageId) => {
1110
1152
  return latestDelete.current(messageId);
1111
1153
  },
1112
1154
  [latestDelete]
1113
1155
  );
1114
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1156
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1115
1157
  const reload = useAsyncCallback(
1116
1158
  (reloadMessageId) => __async(this, null, function* () {
1117
1159
  var _a2;
@@ -1179,7 +1221,7 @@ function useCopilotChatInternal({
1179
1221
  [latestSendMessageFunc]
1180
1222
  );
1181
1223
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1182
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1224
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1183
1225
  (messages) => {
1184
1226
  var _a2, _b2;
1185
1227
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1197,24 +1239,24 @@ function useCopilotChatInternal({
1197
1239
  [latestReload]
1198
1240
  );
1199
1241
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1200
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1242
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1201
1243
  var _a2;
1202
1244
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1203
1245
  }, [latestStop]);
1204
1246
  const latestReset = useUpdatedRef(reset);
1205
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1247
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1206
1248
  return latestReset.current();
1207
1249
  }, [latestReset]);
1208
1250
  const lazyToolRendered = useLazyToolRenderer();
1209
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1251
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1210
1252
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1211
1253
  copilotkit,
1212
1254
  agent,
1213
1255
  agentId: resolvedAgentId,
1214
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1256
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1215
1257
  });
1216
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1217
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1258
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1259
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1218
1260
  let processedMessages = allMessages.map((message) => {
1219
1261
  if (message.role !== "assistant") {
1220
1262
  return message;
@@ -1242,31 +1284,13 @@ function useCopilotChatInternal({
1242
1284
  return message;
1243
1285
  });
1244
1286
  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
1287
  return processedMessages;
1264
1288
  }, [
1265
1289
  agent == null ? void 0 : agent.messages,
1266
1290
  lazyToolRendered,
1267
1291
  allMessages,
1268
1292
  renderCustomMessage,
1269
- legacyCustomMessageRenderer,
1293
+ // legacyCustomMessageRenderer,
1270
1294
  resolvedAgentId
1271
1295
  ]);
1272
1296
  return {
@@ -1278,7 +1302,7 @@ function useCopilotChatInternal({
1278
1302
  stopGeneration: latestStopFunc,
1279
1303
  reset: latestResetFunc,
1280
1304
  deleteMessage: latestDeleteFunc,
1281
- isAvailable: !agentAvailable,
1305
+ isAvailable: agentAvailable,
1282
1306
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1283
1307
  // mcpServers,
1284
1308
  // setMcpServers,
@@ -1295,8 +1319,8 @@ function useCopilotChatInternal({
1295
1319
  };
1296
1320
  }
1297
1321
  function useUpdatedRef(value) {
1298
- const ref = (0, import_react12.useRef)(value);
1299
- (0, import_react12.useEffect)(() => {
1322
+ const ref = (0, import_react15.useRef)(value);
1323
+ (0, import_react15.useEffect)(() => {
1300
1324
  ref.current = value;
1301
1325
  }, [value]);
1302
1326
  return ref;
@@ -1307,20 +1331,19 @@ function useLegacyCoagentRenderer({
1307
1331
  agentId,
1308
1332
  threadId
1309
1333
  }) {
1310
- return (0, import_react12.useMemo)(() => {
1334
+ return (0, import_react15.useMemo)(() => {
1311
1335
  if (!copilotkit || !agent) {
1312
1336
  return null;
1313
1337
  }
1314
1338
  return ({ message, position }) => {
1315
1339
  var _a;
1316
1340
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1317
- const existingRunId = copilotkit.getRunIdForMessage(
1318
- agentId,
1319
- effectiveThreadId,
1320
- message.id
1321
- );
1341
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1322
1342
  const runId = existingRunId || `pending:${message.id}`;
1323
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1343
+ const messageIndex = Math.max(
1344
+ agent.messages.findIndex((msg) => msg.id === message.id),
1345
+ 0
1346
+ );
1324
1347
  const bridgeProps = {
1325
1348
  message,
1326
1349
  position,
@@ -1331,7 +1354,7 @@ function useLegacyCoagentRenderer({
1331
1354
  agentId,
1332
1355
  stateSnapshot: message.state
1333
1356
  };
1334
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1357
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1335
1358
  };
1336
1359
  }, [agent, agentId, copilotkit, threadId]);
1337
1360
  }