@copilotkit/react-core 1.50.0-beta.8 → 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 (60) hide show
  1. package/CHANGELOG.md +12 -0
  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-Y2L7KDVW.mjs → chunk-B5ELMVT7.mjs} +2 -2
  6. package/dist/{chunk-ZU6ZBX4E.mjs → chunk-FYMZKPOL.mjs} +4 -4
  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-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  13. package/dist/components/copilot-provider/index.mjs +4 -4
  14. package/dist/components/index.mjs +4 -4
  15. package/dist/hooks/index.d.ts +1 -1
  16. package/dist/hooks/index.js +121 -149
  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 +2 -3
  34. package/dist/hooks/use-copilot-readable.js.map +1 -1
  35. package/dist/hooks/use-copilot-readable.mjs +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +114 -142
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +32 -32
  40. package/dist/lib/copilot-task.mjs +5 -5
  41. package/dist/lib/index.mjs +5 -5
  42. package/dist/types/index.mjs +1 -1
  43. package/dist/utils/index.mjs +3 -3
  44. package/package.json +5 -5
  45. package/src/hooks/index.ts +2 -2
  46. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  47. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  48. package/src/hooks/use-copilot-readable.ts +2 -4
  49. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  50. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  51. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  52. package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
  53. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  54. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  55. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  56. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  57. /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  58. /package/dist/{chunk-ZU6ZBX4E.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
  59. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  60. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.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_react15 = require("react");
86
+ var import_react13 = require("react");
87
87
 
88
88
  // src/context/copilot-context.tsx
89
89
  var import_react = __toESM(require("react"));
@@ -472,7 +472,7 @@ function useLangGraphInterruptRender(agent) {
472
472
  }
473
473
 
474
474
  // src/hooks/use-copilot-chat_internal.ts
475
- var import_react16 = require("@copilotkitnext/react");
475
+ var import_react14 = require("@copilotkitnext/react");
476
476
 
477
477
  // src/hooks/use-lazy-tool-renderer.tsx
478
478
  var import_react9 = require("@copilotkitnext/react");
@@ -499,40 +499,6 @@ function useLazyToolRenderer() {
499
499
  );
500
500
  }
501
501
 
502
- // src/hooks/use-configure-chat-suggestions.tsx
503
- var import_react11 = require("@copilotkitnext/react");
504
- var import_react12 = require("react");
505
- function useConfigureChatSuggestions(config, dependencies = []) {
506
- var _a;
507
- const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
508
- const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
509
- const { copilotkit } = (0, import_react11.useCopilotKit)();
510
- const available = config.available === "enabled" ? "always" : config.available;
511
- const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
512
- available,
513
- consumerAgentId: resolvedAgentId
514
- // Use chatConfig.agentId here
515
- });
516
- (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
517
- const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
518
- (0, import_react12.useEffect)(() => {
519
- if (finalSuggestionConfig.available === "disabled")
520
- return;
521
- const subscription = copilotkit.subscribe({
522
- onAgentsChanged: () => {
523
- const agent = copilotkit.getAgent(resolvedAgentId);
524
- if (agent && !agent.isRunning && !result.suggestions.length) {
525
- copilotkit.reloadSuggestions(resolvedAgentId);
526
- }
527
- }
528
- });
529
- return () => {
530
- subscription.unsubscribe();
531
- };
532
- }, [resolvedAgentId]);
533
- return result;
534
- }
535
-
536
502
  // ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
537
503
  var import_zod = require("zod");
538
504
  var import_zod2 = require("zod");
@@ -939,8 +905,8 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
939
905
  ]);
940
906
 
941
907
  // src/hooks/use-coagent-state-render-bridge.tsx
942
- var import_react13 = require("@copilotkitnext/react");
943
- var import_react14 = require("react");
908
+ var import_react11 = require("@copilotkitnext/react");
909
+ var import_react12 = require("react");
944
910
  var import_shared3 = require("@copilotkit/shared");
945
911
  function getStateWithoutConstantKeys(state) {
946
912
  if (!state)
@@ -967,11 +933,11 @@ function useCoagentStateRenderBridge(agentId, props) {
967
933
  var _a;
968
934
  const { stateSnapshot, messageIndexInRun, message } = props;
969
935
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
970
- const { agent } = (0, import_react13.useAgent)({ agentId });
971
- const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
936
+ const { agent } = (0, import_react11.useAgent)({ agentId });
937
+ const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
972
938
  const runId = (_a = props.runId) != null ? _a : message.runId;
973
939
  const effectiveRunId = runId || "pending";
974
- (0, import_react14.useEffect)(() => {
940
+ (0, import_react12.useEffect)(() => {
975
941
  if (!agent)
976
942
  return;
977
943
  const subscriber = {
@@ -991,7 +957,7 @@ function useCoagentStateRenderBridge(agentId, props) {
991
957
  unsubscribe();
992
958
  };
993
959
  }, [agentId, nodeName]);
994
- const getStateRender = (0, import_react14.useCallback)(
960
+ const getStateRender = (0, import_react12.useCallback)(
995
961
  (messageId) => {
996
962
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
997
963
  if (claimsRef.current[messageId]) {
@@ -1033,7 +999,7 @@ function useCoagentStateRenderBridge(agentId, props) {
1033
999
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1034
1000
  return true;
1035
1001
  };
1036
- return (0, import_react14.useMemo)(() => {
1002
+ return (0, import_react12.useMemo)(() => {
1037
1003
  var _a2, _b, _c;
1038
1004
  if (messageIndexInRun !== 0) {
1039
1005
  return null;
@@ -1093,35 +1059,17 @@ function CoAgentStateRenderBridge(props) {
1093
1059
  }
1094
1060
 
1095
1061
  // src/hooks/use-copilot-chat_internal.ts
1096
- function useConfigureSuggestions2(suggestions) {
1097
- let suggestionsConfig;
1098
- if (Array.isArray(suggestions)) {
1099
- suggestionsConfig = {
1100
- suggestions,
1101
- available: "always"
1102
- };
1103
- } else if (suggestions === "auto") {
1104
- suggestionsConfig = {
1105
- available: suggestions === "auto" ? "always" : "disabled",
1106
- instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
1107
- };
1108
- } else {
1109
- suggestionsConfig = { available: "disabled" };
1110
- }
1111
- useConfigureChatSuggestions(suggestionsConfig);
1112
- }
1113
1062
  function useCopilotChatInternal({
1114
1063
  suggestions
1115
1064
  } = {}) {
1116
1065
  var _a, _b, _c;
1117
- const { copilotkit } = (0, import_react16.useCopilotKit)();
1066
+ const { copilotkit } = (0, import_react14.useCopilotKit)();
1118
1067
  const { threadId, agentSession } = useCopilotContext();
1119
- const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1120
- const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1121
- useConfigureSuggestions2(suggestions);
1068
+ const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
1069
+ const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
1122
1070
  const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1123
- const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1124
- (0, import_react15.useEffect)(() => {
1071
+ const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
1072
+ (0, import_react13.useEffect)(() => {
1125
1073
  const connect = (agent2) => __async(this, null, function* () {
1126
1074
  setAgentAvailable(false);
1127
1075
  try {
@@ -1146,7 +1094,7 @@ function useCopilotChatInternal({
1146
1094
  agent == null ? void 0 : agent.setMessages([]);
1147
1095
  agent == null ? void 0 : agent.setState(null);
1148
1096
  };
1149
- const deleteMessage = (0, import_react15.useCallback)(
1097
+ const deleteMessage = (0, import_react13.useCallback)(
1150
1098
  (messageId) => {
1151
1099
  var _a2;
1152
1100
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1157,13 +1105,13 @@ function useCopilotChatInternal({
1157
1105
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1158
1106
  );
1159
1107
  const latestDelete = useUpdatedRef(deleteMessage);
1160
- const latestDeleteFunc = (0, import_react15.useCallback)(
1108
+ const latestDeleteFunc = (0, import_react13.useCallback)(
1161
1109
  (messageId) => {
1162
1110
  return latestDelete.current(messageId);
1163
1111
  },
1164
1112
  [latestDelete]
1165
1113
  );
1166
- const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1114
+ const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
1167
1115
  const reload = useAsyncCallback(
1168
1116
  (reloadMessageId) => __async(this, null, function* () {
1169
1117
  var _a2;
@@ -1230,7 +1178,7 @@ function useCopilotChatInternal({
1230
1178
  }),
1231
1179
  [latestSendMessageFunc]
1232
1180
  );
1233
- const latestSetMessagesFunc = (0, import_react15.useCallback)(
1181
+ const latestSetMessagesFunc = (0, import_react13.useCallback)(
1234
1182
  (messages) => {
1235
1183
  var _a2, _b2;
1236
1184
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1247,16 +1195,16 @@ function useCopilotChatInternal({
1247
1195
  }),
1248
1196
  [latestReload]
1249
1197
  );
1250
- const latestStopFunc = (0, import_react15.useCallback)(() => {
1198
+ const latestStopFunc = (0, import_react13.useCallback)(() => {
1251
1199
  var _a2;
1252
1200
  return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
1253
1201
  }, [agent == null ? void 0 : agent.abortRun]);
1254
1202
  const latestReset = useUpdatedRef(reset);
1255
- const latestResetFunc = (0, import_react15.useCallback)(() => {
1203
+ const latestResetFunc = (0, import_react13.useCallback)(() => {
1256
1204
  return latestReset.current();
1257
1205
  }, [latestReset]);
1258
1206
  const lazyToolRendered = useLazyToolRenderer();
1259
- const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1207
+ const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
1260
1208
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1261
1209
  copilotkit,
1262
1210
  agent,
@@ -1264,7 +1212,7 @@ function useCopilotChatInternal({
1264
1212
  threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1265
1213
  });
1266
1214
  const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1267
- const resolvedMessages = (0, import_react15.useMemo)(() => {
1215
+ const resolvedMessages = (0, import_react13.useMemo)(() => {
1268
1216
  let processedMessages = allMessages.map((message) => {
1269
1217
  if (message.role !== "assistant") {
1270
1218
  return message;
@@ -1301,6 +1249,15 @@ function useCopilotChatInternal({
1301
1249
  // legacyCustomMessageRenderer,
1302
1250
  resolvedAgentId
1303
1251
  ]);
1252
+ const renderedSuggestions = (0, import_react13.useMemo)(() => {
1253
+ if (Array.isArray(suggestions)) {
1254
+ return {
1255
+ suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
1256
+ isLoading: false
1257
+ };
1258
+ }
1259
+ return currentSuggestions;
1260
+ }, [suggestions, currentSuggestions]);
1304
1261
  return {
1305
1262
  messages: resolvedMessages,
1306
1263
  sendMessage: latestSendMessageFunc,
@@ -1314,21 +1271,21 @@ function useCopilotChatInternal({
1314
1271
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1315
1272
  // mcpServers,
1316
1273
  // setMcpServers,
1317
- suggestions: currentSuggestions.suggestions,
1274
+ suggestions: renderedSuggestions.suggestions,
1318
1275
  setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
1319
1276
  generateSuggestions: () => __async(this, null, function* () {
1320
1277
  return copilotkit.reloadSuggestions(resolvedAgentId);
1321
1278
  }),
1322
1279
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
1323
- isLoadingSuggestions: currentSuggestions.isLoading,
1280
+ isLoadingSuggestions: renderedSuggestions.isLoading,
1324
1281
  interrupt,
1325
1282
  agent,
1326
1283
  threadId
1327
1284
  };
1328
1285
  }
1329
1286
  function useUpdatedRef(value) {
1330
- const ref = (0, import_react15.useRef)(value);
1331
- (0, import_react15.useEffect)(() => {
1287
+ const ref = (0, import_react13.useRef)(value);
1288
+ (0, import_react13.useEffect)(() => {
1332
1289
  ref.current = value;
1333
1290
  }, [value]);
1334
1291
  return ref;
@@ -1339,7 +1296,7 @@ function useLegacyCoagentRenderer({
1339
1296
  agentId,
1340
1297
  threadId
1341
1298
  }) {
1342
- return (0, import_react15.useMemo)(() => {
1299
+ return (0, import_react13.useMemo)(() => {
1343
1300
  if (!copilotkit || !agent) {
1344
1301
  return null;
1345
1302
  }
@@ -1362,7 +1319,7 @@ function useLegacyCoagentRenderer({
1362
1319
  agentId,
1363
1320
  stateSnapshot: message.state
1364
1321
  };
1365
- return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1322
+ return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
1366
1323
  };
1367
1324
  }, [agent, agentId, copilotkit, threadId]);
1368
1325
  }