@copilotkit/react-core 1.50.0-beta.7 → 1.50.0-beta.9

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 (62) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/dist/{chunk-EKDPRKZT.mjs → chunk-3775VM7Y.mjs} +14 -26
  3. package/dist/chunk-3775VM7Y.mjs.map +1 -0
  4. package/dist/{chunk-BLDHD6Q2.mjs → chunk-7SHWECGN.mjs} +2 -2
  5. package/dist/{chunk-QSNZUI5G.mjs → chunk-B5ELMVT7.mjs} +2 -2
  6. package/dist/{chunk-WV57GREG.mjs → chunk-FYMZKPOL.mjs} +6 -6
  7. package/dist/chunk-XDFVCQD3.mjs +27 -0
  8. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  9. package/dist/{chunk-KYY2WZSR.mjs → chunk-YJGPIN3R.mjs} +2 -2
  10. package/dist/chunk-Z6JV2LRY.mjs +37 -0
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/components/copilot-provider/copilotkit.mjs +7 -7
  13. package/dist/components/copilot-provider/index.mjs +7 -7
  14. package/dist/components/index.mjs +7 -7
  15. package/dist/hooks/index.d.ts +1 -1
  16. package/dist/hooks/index.js +146 -151
  17. package/dist/hooks/index.js.map +1 -1
  18. package/dist/hooks/index.mjs +24 -24
  19. package/dist/hooks/use-copilot-chat-headless_c.js +39 -82
  20. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  21. package/dist/hooks/use-copilot-chat-headless_c.mjs +3 -4
  22. package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
  23. package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
  24. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  25. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  26. package/dist/hooks/use-copilot-chat.js +37 -80
  27. package/dist/hooks/use-copilot-chat.js.map +1 -1
  28. package/dist/hooks/use-copilot-chat.mjs +3 -4
  29. package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
  30. package/dist/hooks/use-copilot-chat_internal.js +37 -80
  31. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  32. package/dist/hooks/use-copilot-chat_internal.mjs +2 -3
  33. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  34. package/dist/hooks/use-copilot-readable.js +29 -6
  35. package/dist/hooks/use-copilot-readable.js.map +1 -1
  36. package/dist/hooks/use-copilot-readable.mjs +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +139 -144
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +35 -35
  41. package/dist/lib/copilot-task.mjs +8 -8
  42. package/dist/lib/index.mjs +8 -8
  43. package/dist/types/index.mjs +1 -1
  44. package/dist/utils/index.mjs +3 -3
  45. package/package.json +5 -5
  46. package/src/hooks/index.ts +2 -2
  47. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  48. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  49. package/src/hooks/use-copilot-readable.ts +30 -13
  50. package/dist/chunk-2CYJN455.mjs +0 -14
  51. package/dist/chunk-2CYJN455.mjs.map +0 -1
  52. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  53. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  54. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  55. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  56. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  57. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  58. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  59. /package/dist/{chunk-QSNZUI5G.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  60. /package/dist/{chunk-WV57GREG.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
  61. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  62. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
@@ -1,13 +1,25 @@
1
1
  import "../chunk-A6NKSGH3.mjs";
2
- import {
3
- useDefaultTool
4
- } from "../chunk-U2ZRVVKT.mjs";
5
2
  import {
6
3
  useLangGraphInterrupt
7
4
  } from "../chunk-4RRMC7L2.mjs";
8
5
  import {
9
6
  useMakeCopilotDocumentReadable
10
7
  } from "../chunk-7IBF6RBW.mjs";
8
+ import {
9
+ useCopilotReadable
10
+ } from "../chunk-Z6JV2LRY.mjs";
11
+ import {
12
+ useCopilotRuntimeClient
13
+ } from "../chunk-6ESSSQ7Q.mjs";
14
+ import {
15
+ useDefaultTool
16
+ } from "../chunk-U2ZRVVKT.mjs";
17
+ import {
18
+ useCoAgentStateRender
19
+ } from "../chunk-YTQHRJUA.mjs";
20
+ import {
21
+ useCoAgent
22
+ } from "../chunk-ZYTXB6HH.mjs";
11
23
  import {
12
24
  useCopilotAdditionalInstructions
13
25
  } from "../chunk-ABWT4DRT.mjs";
@@ -28,35 +40,23 @@ import {
28
40
  } from "../chunk-7DTB7S5V.mjs";
29
41
  import {
30
42
  useCopilotChatHeadless_c
31
- } from "../chunk-KYY2WZSR.mjs";
43
+ } from "../chunk-YJGPIN3R.mjs";
44
+ import {
45
+ useCopilotChatSuggestions
46
+ } from "../chunk-XDFVCQD3.mjs";
32
47
  import {
33
48
  useCopilotChat
34
- } from "../chunk-BLDHD6Q2.mjs";
49
+ } from "../chunk-7SHWECGN.mjs";
35
50
  import {
36
51
  useCopilotChatInternal
37
- } from "../chunk-EKDPRKZT.mjs";
38
- import {
39
- useLangGraphInterruptRender
40
- } from "../chunk-VV56AVPB.mjs";
52
+ } from "../chunk-3775VM7Y.mjs";
41
53
  import {
42
54
  useLazyToolRenderer
43
55
  } from "../chunk-ZVF5Q6IH.mjs";
44
56
  import {
45
- useCopilotReadable
46
- } from "../chunk-2CYJN455.mjs";
47
- import {
48
- useCopilotRuntimeClient
49
- } from "../chunk-6ESSSQ7Q.mjs";
50
- import {
51
- useCoAgentStateRender
52
- } from "../chunk-YTQHRJUA.mjs";
53
- import {
54
- useCoAgent
55
- } from "../chunk-ZYTXB6HH.mjs";
57
+ useLangGraphInterruptRender
58
+ } from "../chunk-VV56AVPB.mjs";
56
59
  import "../chunk-I76HKHPJ.mjs";
57
- import {
58
- useConfigureChatSuggestions
59
- } from "../chunk-FBVI3LQ6.mjs";
60
60
  import "../chunk-6PUNP7CD.mjs";
61
61
  import "../chunk-O7ARI5CV.mjs";
62
62
  import "../chunk-QNUAXSDP.mjs";
@@ -70,13 +70,13 @@ import "../chunk-SKC7AJIV.mjs";
70
70
  export {
71
71
  useCoAgent,
72
72
  useCoAgentStateRender,
73
- useConfigureChatSuggestions,
74
73
  useCopilotAction,
75
74
  useCopilotAdditionalInstructions,
76
75
  useCopilotAuthenticatedAction_c,
77
76
  useCopilotChat,
78
77
  useCopilotChatHeadless_c,
79
78
  useCopilotChatInternal,
79
+ useCopilotChatSuggestions,
80
80
  useCopilotReadable,
81
81
  useCopilotRuntimeClient,
82
82
  useDefaultTool,
@@ -83,7 +83,7 @@ __export(use_copilot_chat_headless_c_exports, {
83
83
  useCopilotChatHeadless_c: () => useCopilotChatHeadless_c
84
84
  });
85
85
  module.exports = __toCommonJS(use_copilot_chat_headless_c_exports);
86
- var import_react17 = 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"));
@@ -187,7 +187,7 @@ function returnAndThrowInDebug(_value) {
187
187
  }
188
188
 
189
189
  // src/hooks/use-copilot-chat_internal.ts
190
- var import_react15 = require("react");
190
+ var import_react13 = require("react");
191
191
 
192
192
  // src/components/error-boundary/error-utils.tsx
193
193
  var import_react3 = require("react");
@@ -475,7 +475,7 @@ function useLangGraphInterruptRender(agent) {
475
475
  }
476
476
 
477
477
  // src/hooks/use-copilot-chat_internal.ts
478
- var import_react16 = require("@copilotkitnext/react");
478
+ var import_react14 = require("@copilotkitnext/react");
479
479
 
480
480
  // src/hooks/use-lazy-tool-renderer.tsx
481
481
  var import_react9 = require("@copilotkitnext/react");
@@ -502,40 +502,6 @@ function useLazyToolRenderer() {
502
502
  );
503
503
  }
504
504
 
505
- // src/hooks/use-configure-chat-suggestions.tsx
506
- var import_react11 = require("@copilotkitnext/react");
507
- var import_react12 = require("react");
508
- function useConfigureChatSuggestions(config, dependencies = []) {
509
- var _a;
510
- const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
511
- const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
512
- const { copilotkit } = (0, import_react11.useCopilotKit)();
513
- const available = config.available === "enabled" ? "always" : config.available;
514
- const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
515
- available,
516
- consumerAgentId: resolvedAgentId
517
- // Use chatConfig.agentId here
518
- });
519
- (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
520
- const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
521
- (0, import_react12.useEffect)(() => {
522
- if (finalSuggestionConfig.available === "disabled")
523
- return;
524
- const subscription = copilotkit.subscribe({
525
- onAgentsChanged: () => {
526
- const agent = copilotkit.getAgent(resolvedAgentId);
527
- if (agent && !agent.isRunning && !result.suggestions.length) {
528
- copilotkit.reloadSuggestions(resolvedAgentId);
529
- }
530
- }
531
- });
532
- return () => {
533
- subscription.unsubscribe();
534
- };
535
- }, [resolvedAgentId]);
536
- return result;
537
- }
538
-
539
505
  // ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
540
506
  var import_zod = require("zod");
541
507
  var import_zod2 = require("zod");
@@ -942,8 +908,8 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
942
908
  ]);
943
909
 
944
910
  // src/hooks/use-coagent-state-render-bridge.tsx
945
- var import_react13 = require("@copilotkitnext/react");
946
- var import_react14 = require("react");
911
+ var import_react11 = require("@copilotkitnext/react");
912
+ var import_react12 = require("react");
947
913
  var import_shared3 = require("@copilotkit/shared");
948
914
  function getStateWithoutConstantKeys(state) {
949
915
  if (!state)
@@ -970,11 +936,11 @@ function useCoagentStateRenderBridge(agentId, props) {
970
936
  var _a;
971
937
  const { stateSnapshot, messageIndexInRun, message } = props;
972
938
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
973
- const { agent } = (0, import_react13.useAgent)({ agentId });
974
- const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
939
+ const { agent } = (0, import_react11.useAgent)({ agentId });
940
+ const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
975
941
  const runId = (_a = props.runId) != null ? _a : message.runId;
976
942
  const effectiveRunId = runId || "pending";
977
- (0, import_react14.useEffect)(() => {
943
+ (0, import_react12.useEffect)(() => {
978
944
  if (!agent)
979
945
  return;
980
946
  const subscriber = {
@@ -994,7 +960,7 @@ function useCoagentStateRenderBridge(agentId, props) {
994
960
  unsubscribe();
995
961
  };
996
962
  }, [agentId, nodeName]);
997
- const getStateRender = (0, import_react14.useCallback)(
963
+ const getStateRender = (0, import_react12.useCallback)(
998
964
  (messageId) => {
999
965
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
1000
966
  if (claimsRef.current[messageId]) {
@@ -1036,7 +1002,7 @@ function useCoagentStateRenderBridge(agentId, props) {
1036
1002
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1037
1003
  return true;
1038
1004
  };
1039
- return (0, import_react14.useMemo)(() => {
1005
+ return (0, import_react12.useMemo)(() => {
1040
1006
  var _a2, _b, _c;
1041
1007
  if (messageIndexInRun !== 0) {
1042
1008
  return null;
@@ -1096,35 +1062,17 @@ function CoAgentStateRenderBridge(props) {
1096
1062
  }
1097
1063
 
1098
1064
  // src/hooks/use-copilot-chat_internal.ts
1099
- function useConfigureSuggestions2(suggestions) {
1100
- let suggestionsConfig;
1101
- if (Array.isArray(suggestions)) {
1102
- suggestionsConfig = {
1103
- suggestions,
1104
- available: "always"
1105
- };
1106
- } else if (suggestions === "auto") {
1107
- suggestionsConfig = {
1108
- available: suggestions === "auto" ? "always" : "disabled",
1109
- instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
1110
- };
1111
- } else {
1112
- suggestionsConfig = { available: "disabled" };
1113
- }
1114
- useConfigureChatSuggestions(suggestionsConfig);
1115
- }
1116
1065
  function useCopilotChatInternal({
1117
1066
  suggestions
1118
1067
  } = {}) {
1119
1068
  var _a, _b, _c;
1120
- const { copilotkit } = (0, import_react16.useCopilotKit)();
1069
+ const { copilotkit } = (0, import_react14.useCopilotKit)();
1121
1070
  const { threadId, agentSession } = useCopilotContext();
1122
- const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1123
- const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1124
- useConfigureSuggestions2(suggestions);
1071
+ const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
1072
+ const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
1125
1073
  const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1126
- const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1127
- (0, import_react15.useEffect)(() => {
1074
+ const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
1075
+ (0, import_react13.useEffect)(() => {
1128
1076
  const connect = (agent2) => __async(this, null, function* () {
1129
1077
  setAgentAvailable(false);
1130
1078
  try {
@@ -1149,7 +1097,7 @@ function useCopilotChatInternal({
1149
1097
  agent == null ? void 0 : agent.setMessages([]);
1150
1098
  agent == null ? void 0 : agent.setState(null);
1151
1099
  };
1152
- const deleteMessage = (0, import_react15.useCallback)(
1100
+ const deleteMessage = (0, import_react13.useCallback)(
1153
1101
  (messageId) => {
1154
1102
  var _a2;
1155
1103
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1160,13 +1108,13 @@ function useCopilotChatInternal({
1160
1108
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1161
1109
  );
1162
1110
  const latestDelete = useUpdatedRef(deleteMessage);
1163
- const latestDeleteFunc = (0, import_react15.useCallback)(
1111
+ const latestDeleteFunc = (0, import_react13.useCallback)(
1164
1112
  (messageId) => {
1165
1113
  return latestDelete.current(messageId);
1166
1114
  },
1167
1115
  [latestDelete]
1168
1116
  );
1169
- const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1117
+ const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
1170
1118
  const reload = useAsyncCallback(
1171
1119
  (reloadMessageId) => __async(this, null, function* () {
1172
1120
  var _a2;
@@ -1233,7 +1181,7 @@ function useCopilotChatInternal({
1233
1181
  }),
1234
1182
  [latestSendMessageFunc]
1235
1183
  );
1236
- const latestSetMessagesFunc = (0, import_react15.useCallback)(
1184
+ const latestSetMessagesFunc = (0, import_react13.useCallback)(
1237
1185
  (messages) => {
1238
1186
  var _a2, _b2;
1239
1187
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1250,16 +1198,16 @@ function useCopilotChatInternal({
1250
1198
  }),
1251
1199
  [latestReload]
1252
1200
  );
1253
- const latestStopFunc = (0, import_react15.useCallback)(() => {
1201
+ const latestStopFunc = (0, import_react13.useCallback)(() => {
1254
1202
  var _a2;
1255
1203
  return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
1256
1204
  }, [agent == null ? void 0 : agent.abortRun]);
1257
1205
  const latestReset = useUpdatedRef(reset);
1258
- const latestResetFunc = (0, import_react15.useCallback)(() => {
1206
+ const latestResetFunc = (0, import_react13.useCallback)(() => {
1259
1207
  return latestReset.current();
1260
1208
  }, [latestReset]);
1261
1209
  const lazyToolRendered = useLazyToolRenderer();
1262
- const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1210
+ const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
1263
1211
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1264
1212
  copilotkit,
1265
1213
  agent,
@@ -1267,7 +1215,7 @@ function useCopilotChatInternal({
1267
1215
  threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1268
1216
  });
1269
1217
  const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1270
- const resolvedMessages = (0, import_react15.useMemo)(() => {
1218
+ const resolvedMessages = (0, import_react13.useMemo)(() => {
1271
1219
  let processedMessages = allMessages.map((message) => {
1272
1220
  if (message.role !== "assistant") {
1273
1221
  return message;
@@ -1304,6 +1252,15 @@ function useCopilotChatInternal({
1304
1252
  // legacyCustomMessageRenderer,
1305
1253
  resolvedAgentId
1306
1254
  ]);
1255
+ const renderedSuggestions = (0, import_react13.useMemo)(() => {
1256
+ if (Array.isArray(suggestions)) {
1257
+ return {
1258
+ suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
1259
+ isLoading: false
1260
+ };
1261
+ }
1262
+ return currentSuggestions;
1263
+ }, [suggestions, currentSuggestions]);
1307
1264
  return {
1308
1265
  messages: resolvedMessages,
1309
1266
  sendMessage: latestSendMessageFunc,
@@ -1317,21 +1274,21 @@ function useCopilotChatInternal({
1317
1274
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1318
1275
  // mcpServers,
1319
1276
  // setMcpServers,
1320
- suggestions: currentSuggestions.suggestions,
1277
+ suggestions: renderedSuggestions.suggestions,
1321
1278
  setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
1322
1279
  generateSuggestions: () => __async(this, null, function* () {
1323
1280
  return copilotkit.reloadSuggestions(resolvedAgentId);
1324
1281
  }),
1325
1282
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
1326
- isLoadingSuggestions: currentSuggestions.isLoading,
1283
+ isLoadingSuggestions: renderedSuggestions.isLoading,
1327
1284
  interrupt,
1328
1285
  agent,
1329
1286
  threadId
1330
1287
  };
1331
1288
  }
1332
1289
  function useUpdatedRef(value) {
1333
- const ref = (0, import_react15.useRef)(value);
1334
- (0, import_react15.useEffect)(() => {
1290
+ const ref = (0, import_react13.useRef)(value);
1291
+ (0, import_react13.useEffect)(() => {
1335
1292
  ref.current = value;
1336
1293
  }, [value]);
1337
1294
  return ref;
@@ -1342,7 +1299,7 @@ function useLegacyCoagentRenderer({
1342
1299
  agentId,
1343
1300
  threadId
1344
1301
  }) {
1345
- return (0, import_react15.useMemo)(() => {
1302
+ return (0, import_react13.useMemo)(() => {
1346
1303
  if (!copilotkit || !agent) {
1347
1304
  return null;
1348
1305
  }
@@ -1365,7 +1322,7 @@ function useLegacyCoagentRenderer({
1365
1322
  agentId,
1366
1323
  stateSnapshot: message.state
1367
1324
  };
1368
- return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1325
+ return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
1369
1326
  };
1370
1327
  }, [agent, agentId, copilotkit, threadId]);
1371
1328
  }
@@ -1437,7 +1394,7 @@ function useCopilotChatHeadless_c(options = {}) {
1437
1394
  const { copilotApiConfig, setBannerError } = useCopilotContext();
1438
1395
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
1439
1396
  const internalResult = useCopilotChatInternal(options);
1440
- (0, import_react17.useEffect)(() => {
1397
+ (0, import_react15.useEffect)(() => {
1441
1398
  if (!hasPublicApiKey) {
1442
1399
  setBannerError(
1443
1400
  new import_shared4.CopilotKitError({