@copilotkit/react-core 1.5.13 → 1.5.14-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 (111) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-X62FIPVR.mjs → chunk-67W2A4DM.mjs} +5 -5
  3. package/dist/{chunk-N37EFAUX.mjs → chunk-7QGQVBD7.mjs} +2 -2
  4. package/dist/chunk-D34OH4VN.mjs +201 -0
  5. package/dist/chunk-D34OH4VN.mjs.map +1 -0
  6. package/dist/{chunk-6BQUI465.mjs → chunk-DZCTHC4G.mjs} +5 -5
  7. package/dist/{chunk-CBWNO2FP.mjs → chunk-GPWNMXSU.mjs} +2 -2
  8. package/dist/chunk-PMAFHQ7P.mjs +65 -0
  9. package/dist/chunk-PMAFHQ7P.mjs.map +1 -0
  10. package/dist/{chunk-MF4F77OY.mjs → chunk-PMHLIIAI.mjs} +10 -10
  11. package/dist/chunk-PMHLIIAI.mjs.map +1 -0
  12. package/dist/{chunk-YVQNSJ4Z.mjs → chunk-RKYHRYN3.mjs} +1 -1
  13. package/dist/{chunk-YVQNSJ4Z.mjs.map → chunk-RKYHRYN3.mjs.map} +1 -1
  14. package/dist/{chunk-J6UBNKIR.mjs → chunk-S5MSFDGS.mjs} +2 -2
  15. package/dist/{chunk-MYCYEMIM.mjs → chunk-TJTOQRGB.mjs} +35 -30
  16. package/dist/chunk-TJTOQRGB.mjs.map +1 -0
  17. package/dist/chunk-UMQQA6HK.mjs +80 -0
  18. package/dist/chunk-UMQQA6HK.mjs.map +1 -0
  19. package/dist/{chunk-IFBUUIU7.mjs → chunk-V74U56PX.mjs} +8 -10
  20. package/dist/chunk-V74U56PX.mjs.map +1 -0
  21. package/dist/{chunk-VEGDEDID.mjs → chunk-VEQGQAGN.mjs} +2 -2
  22. package/dist/{chunk-EXX267DG.mjs → chunk-YJT6IYNV.mjs} +2 -2
  23. package/dist/components/copilot-provider/copilot-messages.d.ts +4 -12
  24. package/dist/components/copilot-provider/copilot-messages.js +3 -18
  25. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  26. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  27. package/dist/components/copilot-provider/copilotkit-props.d.ts +15 -1
  28. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  29. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  30. package/dist/components/copilot-provider/copilotkit.js +324 -34
  31. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  32. package/dist/components/copilot-provider/copilotkit.mjs +6 -4
  33. package/dist/components/copilot-provider/index.js +324 -34
  34. package/dist/components/copilot-provider/index.js.map +1 -1
  35. package/dist/components/copilot-provider/index.mjs +6 -4
  36. package/dist/components/error-boundary/error-boundary.d.ts +12 -3
  37. package/dist/components/error-boundary/error-boundary.js +324 -18
  38. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  39. package/dist/components/error-boundary/error-boundary.mjs +3 -1
  40. package/dist/components/index.js +324 -34
  41. package/dist/components/index.js.map +1 -1
  42. package/dist/components/index.mjs +6 -4
  43. package/dist/components/usage-banner.d.ts +22 -0
  44. package/dist/components/usage-banner.js +226 -0
  45. package/dist/components/usage-banner.js.map +1 -0
  46. package/dist/components/usage-banner.mjs +10 -0
  47. package/dist/components/usage-banner.mjs.map +1 -0
  48. package/dist/context/copilot-context.d.ts +3 -3
  49. package/dist/context/copilot-context.js.map +1 -1
  50. package/dist/context/copilot-context.mjs +1 -1
  51. package/dist/context/index.js.map +1 -1
  52. package/dist/context/index.mjs +4 -4
  53. package/dist/hooks/index.d.ts +1 -1
  54. package/dist/hooks/index.js +8 -8
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/index.mjs +19 -17
  57. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  58. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  59. package/dist/hooks/use-coagent.js.map +1 -1
  60. package/dist/hooks/use-coagent.mjs +8 -6
  61. package/dist/hooks/use-copilot-action.js.map +1 -1
  62. package/dist/hooks/use-copilot-action.mjs +2 -2
  63. package/dist/hooks/use-copilot-authenticated-action.d.ts +12 -2
  64. package/dist/hooks/use-copilot-authenticated-action.js +8 -8
  65. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  66. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  67. package/dist/hooks/use-copilot-chat.js.map +1 -1
  68. package/dist/hooks/use-copilot-chat.mjs +7 -5
  69. package/dist/hooks/use-copilot-readable.js.map +1 -1
  70. package/dist/hooks/use-copilot-readable.mjs +2 -2
  71. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  72. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  73. package/dist/index.d.ts +1 -1
  74. package/dist/index.js +341 -51
  75. package/dist/index.js.map +1 -1
  76. package/dist/index.mjs +23 -21
  77. package/dist/lib/copilot-task.js.map +1 -1
  78. package/dist/lib/copilot-task.mjs +7 -5
  79. package/dist/lib/index.js.map +1 -1
  80. package/dist/lib/index.mjs +7 -5
  81. package/dist/lib/status-checker.d.ts +17 -0
  82. package/dist/lib/status-checker.js +102 -0
  83. package/dist/lib/status-checker.js.map +1 -0
  84. package/dist/lib/status-checker.mjs +8 -0
  85. package/dist/lib/status-checker.mjs.map +1 -0
  86. package/dist/utils/extract.js.map +1 -1
  87. package/dist/utils/extract.mjs +6 -4
  88. package/dist/utils/index.js.map +1 -1
  89. package/dist/utils/index.mjs +6 -4
  90. package/package.json +3 -3
  91. package/src/components/copilot-provider/copilot-messages.tsx +2 -2
  92. package/src/components/copilot-provider/copilotkit-props.tsx +16 -1
  93. package/src/components/copilot-provider/copilotkit.tsx +43 -27
  94. package/src/components/error-boundary/error-boundary.tsx +51 -4
  95. package/src/components/usage-banner.tsx +205 -0
  96. package/src/context/copilot-context.tsx +3 -3
  97. package/src/hooks/index.ts +1 -1
  98. package/src/hooks/use-copilot-authenticated-action.ts +17 -7
  99. package/src/lib/status-checker.ts +64 -0
  100. package/dist/chunk-IFBUUIU7.mjs.map +0 -1
  101. package/dist/chunk-MF4F77OY.mjs.map +0 -1
  102. package/dist/chunk-MYCYEMIM.mjs.map +0 -1
  103. package/dist/chunk-X47CUJJT.mjs +0 -37
  104. package/dist/chunk-X47CUJJT.mjs.map +0 -1
  105. /package/dist/{chunk-X62FIPVR.mjs.map → chunk-67W2A4DM.mjs.map} +0 -0
  106. /package/dist/{chunk-N37EFAUX.mjs.map → chunk-7QGQVBD7.mjs.map} +0 -0
  107. /package/dist/{chunk-6BQUI465.mjs.map → chunk-DZCTHC4G.mjs.map} +0 -0
  108. /package/dist/{chunk-CBWNO2FP.mjs.map → chunk-GPWNMXSU.mjs.map} +0 -0
  109. /package/dist/{chunk-J6UBNKIR.mjs.map → chunk-S5MSFDGS.mjs.map} +0 -0
  110. /package/dist/{chunk-VEGDEDID.mjs.map → chunk-VEQGQAGN.mjs.map} +0 -0
  111. /package/dist/{chunk-EXX267DG.mjs.map → chunk-YJT6IYNV.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -94,7 +94,7 @@ __export(src_exports, {
94
94
  useCoAgent: () => useCoAgent,
95
95
  useCoAgentStateRender: () => useCoAgentStateRender,
96
96
  useCopilotAction: () => useCopilotAction,
97
- useCopilotAuthenticatedAction: () => useCopilotAuthenticatedAction,
97
+ useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
98
98
  useCopilotChat: () => useCopilotChat,
99
99
  useCopilotContext: () => useCopilotContext,
100
100
  useCopilotMessagesContext: () => useCopilotMessagesContext,
@@ -321,7 +321,7 @@ function setsHaveIntersection(setA, setB) {
321
321
 
322
322
  // src/components/copilot-provider/copilotkit.tsx
323
323
  var import_react_dom = require("react-dom");
324
- var import_shared4 = require("@copilotkit/shared");
324
+ var import_shared7 = require("@copilotkit/shared");
325
325
 
326
326
  // src/hooks/use-flat-category-store.ts
327
327
  var import_react3 = require("react");
@@ -412,19 +412,18 @@ function useCopilotMessagesContext() {
412
412
  // src/components/copilot-provider/copilot-messages.tsx
413
413
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
414
414
  var import_jsx_runtime = require("react/jsx-runtime");
415
- function CopilotMessages(_a) {
416
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
415
+ function CopilotMessages({ children }) {
417
416
  const [messages, setMessages] = (0, import_react5.useState)([]);
418
417
  const { threadId, agentSession, runtimeClient } = useCopilotContext();
419
418
  (0, import_react5.useEffect)(() => {
420
419
  if (agentSession == null ? void 0 : agentSession.agentName) {
421
420
  const fetchAgentState = () => __async(this, null, function* () {
422
- var _a2, _b2, _c, _d;
421
+ var _a, _b, _c, _d;
423
422
  const result = yield runtimeClient.loadAgentState({
424
423
  threadId,
425
424
  agentName: agentSession.agentName
426
425
  });
427
- if ((_b2 = (_a2 = result.data) == null ? void 0 : _a2.loadAgentState) == null ? void 0 : _b2.threadExists) {
426
+ if ((_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.threadExists) {
428
427
  const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(
429
428
  JSON.parse(((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.messages) || "[]")
430
429
  );
@@ -872,20 +871,308 @@ function getHostname() {
872
871
 
873
872
  // src/components/error-boundary/error-boundary.tsx
874
873
  var import_react9 = __toESM(require("react"));
874
+ var import_shared6 = require("@copilotkit/shared");
875
+
876
+ // src/lib/status-checker.ts
877
+ var import_shared4 = require("@copilotkit/shared");
878
+ var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
879
+ var StatusChecker = class {
880
+ constructor() {
881
+ this.activeKey = null;
882
+ this.intervalId = null;
883
+ this.instanceCount = 0;
884
+ this.lastResponse = null;
885
+ }
886
+ start(publicApiKey, onUpdate) {
887
+ return __async(this, null, function* () {
888
+ this.instanceCount++;
889
+ if (this.activeKey === publicApiKey)
890
+ return;
891
+ if (this.intervalId)
892
+ clearInterval(this.intervalId);
893
+ const checkStatus = () => __async(this, null, function* () {
894
+ try {
895
+ const response = yield fetch(`${import_shared4.COPILOT_CLOUD_API_URL}/ciu`, {
896
+ method: "GET",
897
+ headers: {
898
+ [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
899
+ }
900
+ }).then((response2) => response2.json());
901
+ this.lastResponse = response;
902
+ onUpdate == null ? void 0 : onUpdate(response);
903
+ return response;
904
+ } catch (error) {
905
+ return null;
906
+ }
907
+ });
908
+ const initialResponse = yield checkStatus();
909
+ this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
910
+ this.activeKey = publicApiKey;
911
+ return initialResponse;
912
+ });
913
+ }
914
+ getLastResponse() {
915
+ return this.lastResponse;
916
+ }
917
+ stop() {
918
+ this.instanceCount--;
919
+ if (this.instanceCount === 0) {
920
+ if (this.intervalId) {
921
+ clearInterval(this.intervalId);
922
+ this.intervalId = null;
923
+ this.activeKey = null;
924
+ this.lastResponse = null;
925
+ }
926
+ }
927
+ }
928
+ };
929
+
930
+ // src/components/usage-banner.tsx
931
+ var import_shared5 = require("@copilotkit/shared");
875
932
  var import_jsx_runtime5 = require("react/jsx-runtime");
933
+ var defaultIcons = {
934
+ [import_shared5.Severity.Error]: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
935
+ "svg",
936
+ {
937
+ viewBox: "0 0 24 24",
938
+ width: "20",
939
+ height: "20",
940
+ stroke: "currentColor",
941
+ strokeWidth: "2",
942
+ fill: "none",
943
+ strokeLinecap: "round",
944
+ strokeLinejoin: "round",
945
+ children: [
946
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
947
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
948
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
949
+ ]
950
+ }
951
+ )
952
+ };
953
+ function UsageBanner({
954
+ severity = import_shared5.Severity.Error,
955
+ message = "",
956
+ icon,
957
+ actions
958
+ }) {
959
+ if (!message || !severity) {
960
+ return null;
961
+ }
962
+ const Icon = icon || defaultIcons[severity];
963
+ const bgColor = {
964
+ info: "#dbeafe",
965
+ warning: "#fef3c7",
966
+ error: "#fee2e2"
967
+ }[severity];
968
+ const textColor = {
969
+ info: "#1e40af",
970
+ warning: "#854d0e",
971
+ error: "#991b1b"
972
+ }[severity];
973
+ const iconColor = {
974
+ info: "#3b82f6",
975
+ warning: "#eab308",
976
+ error: "#ef4444"
977
+ }[severity];
978
+ const primaryButtonColor = {
979
+ info: "#3b82f6",
980
+ warning: "#eab308",
981
+ error: "#ef4444"
982
+ }[severity];
983
+ const primaryButtonHoverColor = {
984
+ info: "#2563eb",
985
+ warning: "#ca8a04",
986
+ error: "#dc2626"
987
+ }[severity];
988
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
989
+ "div",
990
+ {
991
+ style: {
992
+ position: "fixed",
993
+ bottom: "16px",
994
+ left: "50%",
995
+ transform: "translateX(-50%)",
996
+ maxWidth: "90%",
997
+ zIndex: 9999
998
+ },
999
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1000
+ "div",
1001
+ {
1002
+ style: {
1003
+ display: "flex",
1004
+ flexWrap: "wrap",
1005
+ alignItems: "center",
1006
+ gap: "12px",
1007
+ borderRadius: "9999px",
1008
+ border: "1px solid #e5e7eb",
1009
+ backgroundColor: bgColor,
1010
+ padding: "8px 16px",
1011
+ boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)"
1012
+ },
1013
+ children: [
1014
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { color: iconColor }, children: Icon }),
1015
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1016
+ "span",
1017
+ {
1018
+ style: {
1019
+ flex: 1,
1020
+ fontSize: "14px",
1021
+ fontWeight: 500,
1022
+ color: textColor,
1023
+ whiteSpace: "normal",
1024
+ wordBreak: "break-word"
1025
+ },
1026
+ children: message
1027
+ }
1028
+ ),
1029
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1030
+ "div",
1031
+ {
1032
+ style: {
1033
+ display: "flex",
1034
+ gap: "8px",
1035
+ flexWrap: "wrap"
1036
+ },
1037
+ children: [
1038
+ (actions == null ? void 0 : actions.secondary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1039
+ "button",
1040
+ {
1041
+ onClick: actions.secondary.onClick,
1042
+ style: {
1043
+ borderRadius: "9999px",
1044
+ padding: "4px 12px",
1045
+ fontSize: "14px",
1046
+ fontWeight: 500,
1047
+ color: textColor,
1048
+ backgroundColor: "transparent",
1049
+ border: "none",
1050
+ cursor: "pointer",
1051
+ transition: "background-color 0.2s"
1052
+ },
1053
+ onMouseOver: (e) => e.currentTarget.style.backgroundColor = "rgba(255,255,255,0.5)",
1054
+ onMouseOut: (e) => e.currentTarget.style.backgroundColor = "transparent",
1055
+ children: actions.secondary.label
1056
+ }
1057
+ ),
1058
+ (actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1059
+ "button",
1060
+ {
1061
+ onClick: actions.primary.onClick,
1062
+ style: {
1063
+ borderRadius: "9999px",
1064
+ padding: "4px 12px",
1065
+ fontSize: "14px",
1066
+ fontWeight: 500,
1067
+ color: "#fff",
1068
+ backgroundColor: primaryButtonColor,
1069
+ border: "none",
1070
+ cursor: "pointer",
1071
+ transition: "background-color 0.2s"
1072
+ },
1073
+ onMouseOver: (e) => e.currentTarget.style.backgroundColor = primaryButtonHoverColor,
1074
+ onMouseOut: (e) => e.currentTarget.style.backgroundColor = primaryButtonColor,
1075
+ children: actions.primary.label
1076
+ }
1077
+ )
1078
+ ]
1079
+ }
1080
+ )
1081
+ ]
1082
+ }
1083
+ )
1084
+ }
1085
+ );
1086
+ }
1087
+ function renderCopilotKitUsage(error) {
1088
+ switch (error.name) {
1089
+ case import_shared5.ERROR_NAMES.CONFIGURATION_ERROR:
1090
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UsageBanner, { severity: error.severity, message: error.message });
1091
+ case import_shared5.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
1092
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1093
+ UsageBanner,
1094
+ {
1095
+ severity: error.severity,
1096
+ message: error.message,
1097
+ actions: {
1098
+ primary: {
1099
+ label: "Sign In",
1100
+ onClick: () => {
1101
+ window.location.href = "https://cloud.copilotkit.ai";
1102
+ }
1103
+ }
1104
+ }
1105
+ }
1106
+ );
1107
+ case import_shared5.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
1108
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1109
+ UsageBanner,
1110
+ {
1111
+ severity: error.severity,
1112
+ message: error.message,
1113
+ actions: {
1114
+ primary: {
1115
+ label: "Upgrade",
1116
+ onClick: () => {
1117
+ window.location.href = "https://copilotkit.ai/";
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ );
1123
+ }
1124
+ }
1125
+
1126
+ // src/components/error-boundary/error-boundary.tsx
1127
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1128
+ var statusChecker = new StatusChecker();
876
1129
  var CopilotErrorBoundary = class extends import_react9.default.Component {
877
1130
  constructor(props) {
878
1131
  super(props);
879
- this.state = { hasError: false };
1132
+ this.state = {
1133
+ hasError: false
1134
+ };
880
1135
  }
881
1136
  static getDerivedStateFromError(error) {
882
1137
  return { hasError: true, error };
883
1138
  }
1139
+ componentDidMount() {
1140
+ if (this.props.publicApiKey) {
1141
+ statusChecker.start(this.props.publicApiKey, (newStatus) => {
1142
+ this.setState((prevState) => {
1143
+ var _a;
1144
+ if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
1145
+ return { status: newStatus != null ? newStatus : void 0 };
1146
+ }
1147
+ return null;
1148
+ });
1149
+ });
1150
+ }
1151
+ }
1152
+ componentWillUnmount() {
1153
+ statusChecker.stop();
1154
+ }
884
1155
  componentDidCatch(error, errorInfo) {
885
1156
  console.error("CopilotKit Error:", error, errorInfo);
886
1157
  }
887
1158
  render() {
888
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
1159
+ var _a, _b;
1160
+ if (this.state.hasError) {
1161
+ if (this.state.error instanceof import_shared6.CopilotKitError) {
1162
+ return renderCopilotKitUsage(this.state.error);
1163
+ }
1164
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
1165
+ }
1166
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1167
+ this.props.children,
1168
+ this.props.showUsageBanner ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1169
+ UsageBanner,
1170
+ {
1171
+ severity: (_a = this.state.status) == null ? void 0 : _a.severity,
1172
+ message: (_b = this.state.status) == null ? void 0 : _b.message
1173
+ }
1174
+ ) : null
1175
+ ] });
889
1176
  }
890
1177
  };
891
1178
  function ErrorToast2({ error, children }) {
@@ -899,21 +1186,17 @@ function ErrorToast2({ error, children }) {
899
1186
  }
900
1187
 
901
1188
  // src/components/copilot-provider/copilotkit.tsx
902
- var import_jsx_runtime6 = require("react/jsx-runtime");
1189
+ var import_jsx_runtime7 = require("react/jsx-runtime");
903
1190
  function CopilotKit(_a) {
904
1191
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
905
1192
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
906
1193
  const enabled = shouldShowDevConsole(showDevConsole);
907
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
1194
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotErrorBoundary, { publicApiKey: props.publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
908
1195
  }
909
- function CopilotKitInternal(_a) {
910
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
911
- if (!props.runtimeUrl && !props.publicApiKey) {
912
- throw new Error(
913
- "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
914
- );
915
- }
916
- const chatApiEndpoint = props.runtimeUrl || import_shared4.COPILOT_CLOUD_CHAT_URL;
1196
+ function CopilotKitInternal(cpkProps) {
1197
+ const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
1198
+ validateProps(cpkProps);
1199
+ const chatApiEndpoint = props.runtimeUrl || import_shared7.COPILOT_CLOUD_CHAT_URL;
917
1200
  const [actions, setActions] = (0, import_react10.useState)({});
918
1201
  const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
919
1202
  const chatComponentsCache = (0, import_react10.useRef)({
@@ -1007,15 +1290,8 @@ ${nonDocumentStrings}`;
1007
1290
  },
1008
1291
  [removeDocument]
1009
1292
  );
1010
- if (!props.publicApiKey) {
1011
- if (props.cloudRestrictToTopic) {
1012
- throw new Error(
1013
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
1014
- );
1015
- }
1016
- }
1017
1293
  const copilotApiConfig = (0, import_react10.useMemo)(() => {
1018
- var _a2, _b2;
1294
+ var _a2, _b;
1019
1295
  let cloud = void 0;
1020
1296
  if (props.publicApiKey) {
1021
1297
  cloud = {
@@ -1024,7 +1300,7 @@ ${nonDocumentStrings}`;
1024
1300
  restrictToTopic: {
1025
1301
  enabled: props.cloudRestrictToTopic ? true : false,
1026
1302
  validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
1027
- invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
1303
+ invalidTopics: ((_b = props.cloudRestrictToTopic) == null ? void 0 : _b.invalidTopics) || []
1028
1304
  }
1029
1305
  }
1030
1306
  }
@@ -1061,7 +1337,7 @@ ${nonDocumentStrings}`;
1061
1337
  }
1062
1338
  return acc;
1063
1339
  }, {});
1064
- return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1340
+ return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1065
1341
  }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
1066
1342
  const runtimeClient = useCopilotRuntimeClient({
1067
1343
  url: copilotApiConfig.chatApiEndpoint,
@@ -1109,7 +1385,7 @@ ${nonDocumentStrings}`;
1109
1385
  };
1110
1386
  }
1111
1387
  const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
1112
- const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared4.randomUUID)());
1388
+ const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared7.randomUUID)());
1113
1389
  const setThreadId = (0, import_react10.useCallback)(
1114
1390
  (value) => {
1115
1391
  if (props.threadId) {
@@ -1127,7 +1403,7 @@ ${nonDocumentStrings}`;
1127
1403
  const [runId, setRunId] = (0, import_react10.useState)(null);
1128
1404
  const chatAbortControllerRef = (0, import_react10.useRef)(null);
1129
1405
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
1130
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1406
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1131
1407
  CopilotContext.Provider,
1132
1408
  {
1133
1409
  value: {
@@ -1169,19 +1445,19 @@ ${nonDocumentStrings}`;
1169
1445
  setRunId,
1170
1446
  chatAbortControllerRef,
1171
1447
  availableAgents,
1172
- authConfig: props.authConfig,
1173
- authStates,
1174
- setAuthStates,
1448
+ authConfig_c: props.authConfig_c,
1449
+ authStates_c: authStates,
1450
+ setAuthStates_c: setAuthStates,
1175
1451
  extensions,
1176
1452
  setExtensions
1177
1453
  },
1178
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
1454
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
1179
1455
  }
1180
1456
  );
1181
1457
  }
1182
1458
  var defaultCopilotContextCategories = ["global"];
1183
1459
  function entryPointsToFunctionCallHandler(actions) {
1184
- return (_0) => __async(this, [_0], function* ({ messages, name, args }) {
1460
+ return (_0) => __async(this, [_0], function* ({ name, args }) {
1185
1461
  let actionsByFunctionName = {};
1186
1462
  for (let action2 of actions) {
1187
1463
  actionsByFunctionName[action2.name] = action2;
@@ -1205,6 +1481,20 @@ function entryPointsToFunctionCallHandler(actions) {
1205
1481
  return result;
1206
1482
  });
1207
1483
  }
1484
+ function formatFeatureName(featureName) {
1485
+ return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
1486
+ }
1487
+ function validateProps(props) {
1488
+ const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
1489
+ if (!props.runtimeUrl && !props.publicApiKey) {
1490
+ throw new import_shared7.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
1491
+ }
1492
+ if (cloudFeatures.length > 0 && !props.publicApiKey) {
1493
+ throw new import_shared7.MissingPublicApiKeyError(
1494
+ `Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
1495
+ );
1496
+ }
1497
+ }
1208
1498
 
1209
1499
  // src/hooks/use-copilot-chat.ts
1210
1500
  var import_react12 = require("react");
@@ -1212,12 +1502,12 @@ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1212
1502
 
1213
1503
  // src/hooks/use-chat.ts
1214
1504
  var import_react11 = require("react");
1215
- var import_shared6 = require("@copilotkit/shared");
1505
+ var import_shared9 = require("@copilotkit/shared");
1216
1506
  var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
1217
1507
 
1218
1508
  // src/types/frontend-action.ts
1219
1509
  var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1220
- var import_shared5 = require("@copilotkit/shared");
1510
+ var import_shared8 = require("@copilotkit/shared");
1221
1511
  function processActionsForRuntimeRequest(actions) {
1222
1512
  const filteredActions = actions.filter(
1223
1513
  (action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
@@ -1233,7 +1523,7 @@ function processActionsForRuntimeRequest(actions) {
1233
1523
  return {
1234
1524
  name: action.name,
1235
1525
  description: action.description || "",
1236
- jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || [])),
1526
+ jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || [])),
1237
1527
  available
1238
1528
  };
1239
1529
  });
@@ -1275,7 +1565,7 @@ function useChat(options) {
1275
1565
  const extensionsRef = (0, import_react11.useRef)(extensions);
1276
1566
  extensionsRef.current = extensions;
1277
1567
  const publicApiKey = copilotConfig.publicApiKey;
1278
- const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1568
+ const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared9.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1279
1569
  const runtimeClient = useCopilotRuntimeClient({
1280
1570
  url: copilotConfig.chatApiEndpoint,
1281
1571
  publicApiKey: copilotConfig.publicApiKey,
@@ -1423,7 +1713,7 @@ function useChat(options) {
1423
1713
  } else {
1424
1714
  if (agentLock) {
1425
1715
  setAgentSession({
1426
- threadId: (0, import_shared6.randomId)(),
1716
+ threadId: (0, import_shared9.randomId)(),
1427
1717
  agentName: agentLock,
1428
1718
  nodeName: void 0
1429
1719
  });
@@ -1817,11 +2107,11 @@ ${additionalInstructions}` : "");
1817
2107
  }
1818
2108
 
1819
2109
  // src/hooks/use-copilot-action.ts
1820
- var import_shared7 = require("@copilotkit/shared");
2110
+ var import_shared10 = require("@copilotkit/shared");
1821
2111
  var import_react13 = require("react");
1822
2112
  function useCopilotAction(action, dependencies) {
1823
2113
  const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
1824
- const idRef = (0, import_react13.useRef)((0, import_shared7.randomId)());
2114
+ const idRef = (0, import_react13.useRef)((0, import_shared10.randomId)());
1825
2115
  const renderAndWaitRef = (0, import_react13.useRef)(null);
1826
2116
  action = __spreadValues({}, action);
1827
2117
  if (
@@ -1910,7 +2200,7 @@ function isFrontendAction(action) {
1910
2200
 
1911
2201
  // src/hooks/use-coagent-state-render.ts
1912
2202
  var import_react14 = require("react");
1913
- var import_shared8 = require("@copilotkit/shared");
2203
+ var import_shared11 = require("@copilotkit/shared");
1914
2204
  function useCoAgentStateRender(action, dependencies) {
1915
2205
  const {
1916
2206
  setCoAgentStateRender,
@@ -1919,7 +2209,7 @@ function useCoAgentStateRender(action, dependencies) {
1919
2209
  chatComponentsCache,
1920
2210
  availableAgents
1921
2211
  } = (0, import_react14.useContext)(CopilotContext);
1922
- const idRef = (0, import_react14.useRef)((0, import_shared8.randomId)());
2212
+ const idRef = (0, import_react14.useRef)((0, import_shared11.randomId)());
1923
2213
  const { addToast } = useToast();
1924
2214
  (0, import_react14.useEffect)(() => {
1925
2215
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
@@ -2148,8 +2438,8 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
2148
2438
  // src/hooks/use-copilot-authenticated-action.ts
2149
2439
  var import_react18 = require("react");
2150
2440
  var import_react19 = __toESM(require("react"));
2151
- function useCopilotAuthenticatedAction(action, dependencies) {
2152
- const { authConfig, authStates, setAuthStates } = useCopilotContext();
2441
+ function useCopilotAuthenticatedAction_c(action, dependencies) {
2442
+ const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
2153
2443
  const pendingActionRef = (0, import_react18.useRef)(null);
2154
2444
  const executeAction = (0, import_react18.useCallback)(
2155
2445
  (props) => {
@@ -2162,14 +2452,14 @@ function useCopilotAuthenticatedAction(action, dependencies) {
2162
2452
  );
2163
2453
  const wrappedRender = (0, import_react18.useCallback)(
2164
2454
  (props) => {
2165
- const isAuthenticated = Object.values(authStates || {}).some(
2455
+ const isAuthenticated = Object.values(authStates_c || {}).some(
2166
2456
  (state) => state.status === "authenticated"
2167
2457
  );
2168
2458
  if (!isAuthenticated) {
2169
2459
  pendingActionRef.current = props;
2170
- return (authConfig == null ? void 0 : authConfig.SignInComponent) ? import_react19.default.createElement(authConfig.SignInComponent, {
2460
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react19.default.createElement(authConfig_c.SignInComponent, {
2171
2461
  onSignInComplete: (authState) => {
2172
- setAuthStates == null ? void 0 : setAuthStates((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2462
+ setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2173
2463
  if (pendingActionRef.current) {
2174
2464
  executeAction(pendingActionRef.current);
2175
2465
  pendingActionRef.current = null;
@@ -2179,7 +2469,7 @@ function useCopilotAuthenticatedAction(action, dependencies) {
2179
2469
  }
2180
2470
  return executeAction(props);
2181
2471
  },
2182
- [action, authStates, setAuthStates]
2472
+ [action, authStates_c, setAuthStates_c]
2183
2473
  );
2184
2474
  useCopilotAction(
2185
2475
  __spreadProps(__spreadValues({}, action), {
@@ -2299,7 +2589,7 @@ ${instructions}
2299
2589
  useCoAgent,
2300
2590
  useCoAgentStateRender,
2301
2591
  useCopilotAction,
2302
- useCopilotAuthenticatedAction,
2592
+ useCopilotAuthenticatedAction_c,
2303
2593
  useCopilotChat,
2304
2594
  useCopilotContext,
2305
2595
  useCopilotMessagesContext,