@copilotkit/react-core 1.8.7 → 1.8.8-next.0

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 (115) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-GOK4PDQO.mjs → chunk-2ZKWBDBN.mjs} +2 -2
  3. package/dist/{chunk-7HP5NS5T.mjs → chunk-364OMMXW.mjs} +5 -5
  4. package/dist/{chunk-7VCWAAWC.mjs → chunk-4EXRQ5D5.mjs} +2 -2
  5. package/dist/{chunk-UDUFMGWQ.mjs → chunk-7WG4MNRX.mjs} +1 -1
  6. package/dist/chunk-7WG4MNRX.mjs.map +1 -0
  7. package/dist/{chunk-5TVV6FJD.mjs → chunk-B3CERZDI.mjs} +2 -2
  8. package/dist/{chunk-KF5SB2VB.mjs → chunk-GBAZTXPQ.mjs} +2 -2
  9. package/dist/{chunk-Y3N54L72.mjs → chunk-HI537DQG.mjs} +38 -23
  10. package/dist/chunk-HI537DQG.mjs.map +1 -0
  11. package/dist/{chunk-JWE4IXSG.mjs → chunk-INRN7B2F.mjs} +2 -2
  12. package/dist/{chunk-KAMKS5U6.mjs → chunk-O54FEOCV.mjs} +8 -10
  13. package/dist/chunk-O54FEOCV.mjs.map +1 -0
  14. package/dist/{chunk-DMQB35FC.mjs → chunk-OSVDTMKA.mjs} +2 -2
  15. package/dist/{chunk-FNTV7DBR.mjs → chunk-QWBJM23V.mjs} +3 -3
  16. package/dist/{chunk-JF5EIUQ7.mjs → chunk-VYSR3S2A.mjs} +4 -4
  17. package/dist/{chunk-FRRPZKXW.mjs → chunk-W3QHAZKD.mjs} +3 -3
  18. package/dist/{chunk-UR6DW5BN.mjs → chunk-XRCQULYN.mjs} +2 -2
  19. package/dist/{chunk-6OMSQLHC.mjs → chunk-ZXJHNU6Q.mjs} +20 -13
  20. package/dist/chunk-ZXJHNU6Q.mjs.map +1 -0
  21. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  22. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  23. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -18
  24. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  25. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  26. package/dist/components/copilot-provider/copilotkit.js +1 -3
  27. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  28. package/dist/components/copilot-provider/copilotkit.mjs +5 -5
  29. package/dist/components/copilot-provider/index.d.ts +1 -1
  30. package/dist/components/copilot-provider/index.js +1 -3
  31. package/dist/components/copilot-provider/index.js.map +1 -1
  32. package/dist/components/copilot-provider/index.mjs +5 -5
  33. package/dist/components/index.d.ts +1 -1
  34. package/dist/components/index.js +1 -3
  35. package/dist/components/index.js.map +1 -1
  36. package/dist/components/index.mjs +5 -5
  37. package/dist/context/copilot-context.d.ts +1 -1
  38. package/dist/context/copilot-context.js.map +1 -1
  39. package/dist/context/copilot-context.mjs +1 -1
  40. package/dist/context/index.d.ts +1 -1
  41. package/dist/context/index.js.map +1 -1
  42. package/dist/context/index.mjs +4 -4
  43. package/dist/{copilot-context-0e923eb1.d.ts → copilot-context-8fb74a85.d.ts} +1 -1
  44. package/dist/hooks/index.d.ts +1 -1
  45. package/dist/hooks/index.js +50 -28
  46. package/dist/hooks/index.js.map +1 -1
  47. package/dist/hooks/index.mjs +27 -27
  48. package/dist/hooks/use-chat.d.ts +1 -1
  49. package/dist/hooks/use-chat.js +19 -12
  50. package/dist/hooks/use-chat.js.map +1 -1
  51. package/dist/hooks/use-chat.mjs +1 -1
  52. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  53. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  54. package/dist/hooks/use-coagent.d.ts +1 -1
  55. package/dist/hooks/use-coagent.js +50 -28
  56. package/dist/hooks/use-coagent.js.map +1 -1
  57. package/dist/hooks/use-coagent.mjs +9 -9
  58. package/dist/hooks/use-copilot-action.js.map +1 -1
  59. package/dist/hooks/use-copilot-action.mjs +2 -2
  60. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  61. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  62. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  63. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  64. package/dist/hooks/use-copilot-chat.d.ts +8 -2
  65. package/dist/hooks/use-copilot-chat.js +50 -28
  66. package/dist/hooks/use-copilot-chat.js.map +1 -1
  67. package/dist/hooks/use-copilot-chat.mjs +8 -8
  68. package/dist/hooks/use-copilot-readable.js.map +1 -1
  69. package/dist/hooks/use-copilot-readable.mjs +2 -2
  70. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  71. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  72. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  73. package/dist/hooks/use-langgraph-interrupt.js +50 -28
  74. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  75. package/dist/hooks/use-langgraph-interrupt.mjs +9 -9
  76. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  77. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.js +51 -31
  80. package/dist/index.js.map +1 -1
  81. package/dist/index.mjs +31 -31
  82. package/dist/lib/copilot-task.d.ts +1 -1
  83. package/dist/lib/copilot-task.js.map +1 -1
  84. package/dist/lib/copilot-task.mjs +6 -6
  85. package/dist/lib/index.d.ts +1 -1
  86. package/dist/lib/index.js.map +1 -1
  87. package/dist/lib/index.mjs +6 -6
  88. package/dist/types/interrupt-action.d.ts +1 -1
  89. package/dist/utils/extract.d.ts +1 -1
  90. package/dist/utils/extract.js.map +1 -1
  91. package/dist/utils/extract.mjs +5 -5
  92. package/dist/utils/index.d.ts +1 -1
  93. package/dist/utils/index.js.map +1 -1
  94. package/dist/utils/index.mjs +5 -5
  95. package/package.json +3 -3
  96. package/src/components/copilot-provider/copilotkit-props.tsx +0 -16
  97. package/src/components/copilot-provider/copilotkit.tsx +0 -2
  98. package/src/context/copilot-context.tsx +1 -1
  99. package/src/hooks/use-chat.ts +30 -4
  100. package/src/hooks/use-copilot-chat.ts +52 -27
  101. package/dist/chunk-6OMSQLHC.mjs.map +0 -1
  102. package/dist/chunk-KAMKS5U6.mjs.map +0 -1
  103. package/dist/chunk-UDUFMGWQ.mjs.map +0 -1
  104. package/dist/chunk-Y3N54L72.mjs.map +0 -1
  105. /package/dist/{chunk-GOK4PDQO.mjs.map → chunk-2ZKWBDBN.mjs.map} +0 -0
  106. /package/dist/{chunk-7HP5NS5T.mjs.map → chunk-364OMMXW.mjs.map} +0 -0
  107. /package/dist/{chunk-7VCWAAWC.mjs.map → chunk-4EXRQ5D5.mjs.map} +0 -0
  108. /package/dist/{chunk-5TVV6FJD.mjs.map → chunk-B3CERZDI.mjs.map} +0 -0
  109. /package/dist/{chunk-KF5SB2VB.mjs.map → chunk-GBAZTXPQ.mjs.map} +0 -0
  110. /package/dist/{chunk-JWE4IXSG.mjs.map → chunk-INRN7B2F.mjs.map} +0 -0
  111. /package/dist/{chunk-DMQB35FC.mjs.map → chunk-OSVDTMKA.mjs.map} +0 -0
  112. /package/dist/{chunk-FNTV7DBR.mjs.map → chunk-QWBJM23V.mjs.map} +0 -0
  113. /package/dist/{chunk-JF5EIUQ7.mjs.map → chunk-VYSR3S2A.mjs.map} +0 -0
  114. /package/dist/{chunk-FRRPZKXW.mjs.map → chunk-W3QHAZKD.mjs.map} +0 -0
  115. /package/dist/{chunk-UR6DW5BN.mjs.map → chunk-XRCQULYN.mjs.map} +0 -0
@@ -1,12 +1,12 @@
1
1
  import "../chunk-YPSGKPDA.mjs";
2
+ import {
3
+ CopilotContext,
4
+ useCopilotContext
5
+ } from "../chunk-7WG4MNRX.mjs";
2
6
  import {
3
7
  CopilotMessagesContext,
4
8
  useCopilotMessagesContext
5
9
  } from "../chunk-DCTJZ742.mjs";
6
- import {
7
- CopilotContext,
8
- useCopilotContext
9
- } from "../chunk-UDUFMGWQ.mjs";
10
10
  import "../chunk-SKC7AJIV.mjs";
11
11
  export {
12
12
  CopilotContext,
@@ -100,7 +100,7 @@ interface CopilotApiConfig {
100
100
  * This is typically derived from the CopilotKitProps and used internally.
101
101
  * @experimental
102
102
  */
103
- mcpEndpoints?: Array<{
103
+ mcpServers?: Array<{
104
104
  endpoint: string;
105
105
  apiKey?: string;
106
106
  }>;
@@ -17,7 +17,7 @@ import '../types/frontend-action.js';
17
17
  import 'react';
18
18
  import '../types/coagent-action.js';
19
19
  import '../types/document-pointer.js';
20
- import '../copilot-context-0e923eb1.js';
20
+ import '../copilot-context-8fb74a85.js';
21
21
  import './use-tree.js';
22
22
  import '../types/chat-suggestion-configuration.js';
23
23
  import '../types/coagent-state.js';
@@ -420,7 +420,7 @@ function useChat(options) {
420
420
  });
421
421
  const runChatCompletion = useAsyncCallback(
422
422
  (previousMessages) => __async(this, null, function* () {
423
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
423
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
424
424
  setIsLoading(true);
425
425
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
426
426
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -441,8 +441,15 @@ function useChat(options) {
441
441
  const systemMessage = makeSystemMessageCallback();
442
442
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
443
443
  const finalProperties = __spreadValues({}, copilotConfig.properties || {});
444
- if (copilotConfig.mcpEndpoints && copilotConfig.mcpEndpoints.length > 0) {
445
- finalProperties.mcpEndpoints = copilotConfig.mcpEndpoints;
444
+ let mcpServersToUse = null;
445
+ if (copilotConfig.mcpServers && Array.isArray(copilotConfig.mcpServers) && copilotConfig.mcpServers.length > 0) {
446
+ mcpServersToUse = copilotConfig.mcpServers;
447
+ } else if (((_a = copilotConfig.properties) == null ? void 0 : _a.mcpServers) && Array.isArray(copilotConfig.properties.mcpServers) && copilotConfig.properties.mcpServers.length > 0) {
448
+ mcpServersToUse = copilotConfig.properties.mcpServers;
449
+ }
450
+ if (mcpServersToUse) {
451
+ finalProperties.mcpServers = mcpServersToUse;
452
+ copilotConfig.mcpServers = mcpServersToUse;
446
453
  }
447
454
  const isAgentRun = agentSessionRef.current !== null;
448
455
  const stream = runtimeClient.asStream(
@@ -458,7 +465,7 @@ function useChat(options) {
458
465
  metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
459
466
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
460
467
  }, copilotConfig.cloud ? {
461
- cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
468
+ cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
462
469
  guardrails: {
463
470
  inputValidationRules: {
464
471
  allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
@@ -484,10 +491,10 @@ function useChat(options) {
484
491
  forwardedParameters: options.forwardedParameters || {}
485
492
  }),
486
493
  properties: finalProperties,
487
- signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
494
+ signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
488
495
  })
489
496
  );
490
- const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
497
+ const guardrailsEnabled = ((_h = (_g = (_f = copilotConfig.cloud) == null ? void 0 : _f.guardrails) == null ? void 0 : _g.input) == null ? void 0 : _h.restrictToTopic.enabled) || false;
491
498
  const reader = stream.getReader();
492
499
  let executedCoAgentStateRenders = [];
493
500
  let followUp = void 0;
@@ -520,7 +527,7 @@ function useChat(options) {
520
527
  setRunId(runIdRef.current);
521
528
  setExtensions(extensionsRef.current);
522
529
  let rawMessagesResponse = value.generateCopilotResponse.messages;
523
- const metaEvents = (_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : [];
530
+ const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
524
531
  (metaEvents != null ? metaEvents : []).forEach((ev) => {
525
532
  if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
526
533
  let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
@@ -547,11 +554,11 @@ function useChat(options) {
547
554
  continue;
548
555
  }
549
556
  newMessages = [];
550
- if (((_j = value.generateCopilotResponse.status) == null ? void 0 : _j.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
557
+ if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
551
558
  newMessages = [
552
559
  new import_runtime_client_gql3.TextMessage({
553
560
  role: import_runtime_client_gql3.MessageRole.Assistant,
554
- content: ((_k = value.generateCopilotResponse.status.details) == null ? void 0 : _k.guardrailsReason) || ""
561
+ content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
555
562
  })
556
563
  ];
557
564
  setMessages([...previousMessages, ...newMessages]);
@@ -686,11 +693,11 @@ function useChat(options) {
686
693
  followUp !== false && // and we executed an action
687
694
  (didExecuteAction || // the last message is a server side result
688
695
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
689
- !((_l = chatAbortControllerRef.current) == null ? void 0 : _l.signal.aborted)
696
+ !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
690
697
  ) {
691
698
  yield new Promise((resolve) => setTimeout(resolve, 10));
692
699
  return yield runChatCompletionRef.current(finalMessages);
693
- } else if ((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted) {
700
+ } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
694
701
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
695
702
  if (message.isActionExecutionMessage()) {
696
703
  return finalMessages.find(
@@ -701,7 +708,7 @@ function useChat(options) {
701
708
  });
702
709
  const repairedMessageIds = repairedMessages.map((message) => message.id);
703
710
  setMessages(repairedMessages);
704
- if ((_n = agentSessionRef.current) == null ? void 0 : _n.nodeName) {
711
+ if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
705
712
  setAgentSession({
706
713
  threadId: agentSessionRef.current.threadId,
707
714
  agentName: agentSessionRef.current.agentName,
@@ -950,21 +957,20 @@ function useCopilotChat(_a = {}) {
950
957
  setLangGraphInterruptAction
951
958
  } = useCopilotContext();
952
959
  const { messages, setMessages } = useCopilotMessagesContext();
953
- const latestGetContextString = useUpdatedRef(getContextString);
954
- const deleteMessage = (0, import_react8.useCallback)(
955
- (messageId) => {
956
- setMessages((prev) => prev.filter((message) => message.id !== messageId));
957
- },
958
- [setMessages]
959
- );
960
- const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
961
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
962
- const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
963
- return new import_runtime_client_gql4.TextMessage({
964
- content: systemMessageMaker(contextString, chatInstructions),
965
- role: import_runtime_client_gql4.Role.System
966
- });
967
- }, [getContextString, makeSystemMessage, chatInstructions]);
960
+ const [mcpServers, setLocalMcpServers] = (0, import_react8.useState)([]);
961
+ (0, import_react8.useEffect)(() => {
962
+ if (mcpServers.length > 0) {
963
+ const serversCopy = [...mcpServers];
964
+ copilotApiConfig.mcpServers = serversCopy;
965
+ if (!copilotApiConfig.properties) {
966
+ copilotApiConfig.properties = {};
967
+ }
968
+ copilotApiConfig.properties.mcpServers = serversCopy;
969
+ }
970
+ }, [mcpServers, copilotApiConfig]);
971
+ const setMcpServers = (0, import_react8.useCallback)((servers) => {
972
+ setLocalMcpServers(servers);
973
+ }, []);
968
974
  const onCoAgentStateRender = useAsyncCallback(
969
975
  (args) => __async(this, null, function* () {
970
976
  var _a2;
@@ -983,6 +989,20 @@ function useCopilotChat(_a = {}) {
983
989
  }),
984
990
  [coAgentStateRenders]
985
991
  );
992
+ const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
993
+ const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
994
+ const contextString = getContextString([], defaultCopilotContextCategories);
995
+ return new import_runtime_client_gql4.TextMessage({
996
+ content: systemMessageMaker(contextString, chatInstructions),
997
+ role: import_runtime_client_gql4.Role.System
998
+ });
999
+ }, [getContextString, makeSystemMessage, chatInstructions]);
1000
+ const deleteMessage = (0, import_react8.useCallback)(
1001
+ (messageId) => {
1002
+ setMessages((prev) => prev.filter((message) => message.id !== messageId));
1003
+ },
1004
+ [setMessages]
1005
+ );
986
1006
  const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
987
1007
  actions: Object.values(actions),
988
1008
  copilotConfig: copilotApiConfig,
@@ -1079,7 +1099,9 @@ function useCopilotChat(_a = {}) {
1079
1099
  reset: latestResetFunc,
1080
1100
  deleteMessage: latestDeleteFunc,
1081
1101
  runChatCompletion: latestRunChatCompletionFunc,
1082
- isLoading
1102
+ isLoading,
1103
+ mcpServers,
1104
+ setMcpServers
1083
1105
  };
1084
1106
  }
1085
1107
  function useUpdatedRef(value) {