@copilotkit/react-core 1.5.13 → 1.5.14

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 +18 -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
@@ -302,7 +302,7 @@ function setsHaveIntersection(setA, setB) {
302
302
 
303
303
  // src/components/copilot-provider/copilotkit.tsx
304
304
  var import_react_dom = require("react-dom");
305
- var import_shared3 = require("@copilotkit/shared");
305
+ var import_shared6 = require("@copilotkit/shared");
306
306
 
307
307
  // src/hooks/use-flat-category-store.ts
308
308
  var import_react3 = require("react");
@@ -384,19 +384,18 @@ var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotCon
384
384
  // src/components/copilot-provider/copilot-messages.tsx
385
385
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
386
386
  var import_jsx_runtime = require("react/jsx-runtime");
387
- function CopilotMessages(_a) {
388
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
387
+ function CopilotMessages({ children }) {
389
388
  const [messages, setMessages] = (0, import_react5.useState)([]);
390
389
  const { threadId, agentSession, runtimeClient } = useCopilotContext();
391
390
  (0, import_react5.useEffect)(() => {
392
391
  if (agentSession == null ? void 0 : agentSession.agentName) {
393
392
  const fetchAgentState = () => __async(this, null, function* () {
394
- var _a2, _b2, _c, _d;
393
+ var _a, _b, _c, _d;
395
394
  const result = yield runtimeClient.loadAgentState({
396
395
  threadId,
397
396
  agentName: agentSession.agentName
398
397
  });
399
- if ((_b2 = (_a2 = result.data) == null ? void 0 : _a2.loadAgentState) == null ? void 0 : _b2.threadExists) {
398
+ if ((_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.threadExists) {
400
399
  const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(
401
400
  JSON.parse(((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.messages) || "[]")
402
401
  );
@@ -698,20 +697,308 @@ function getHostname() {
698
697
 
699
698
  // src/components/error-boundary/error-boundary.tsx
700
699
  var import_react9 = __toESM(require("react"));
700
+ var import_shared5 = require("@copilotkit/shared");
701
+
702
+ // src/lib/status-checker.ts
703
+ var import_shared3 = require("@copilotkit/shared");
704
+ var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
705
+ var StatusChecker = class {
706
+ constructor() {
707
+ this.activeKey = null;
708
+ this.intervalId = null;
709
+ this.instanceCount = 0;
710
+ this.lastResponse = null;
711
+ }
712
+ start(publicApiKey, onUpdate) {
713
+ return __async(this, null, function* () {
714
+ this.instanceCount++;
715
+ if (this.activeKey === publicApiKey)
716
+ return;
717
+ if (this.intervalId)
718
+ clearInterval(this.intervalId);
719
+ const checkStatus = () => __async(this, null, function* () {
720
+ try {
721
+ const response = yield fetch(`${import_shared3.COPILOT_CLOUD_API_URL}/ciu`, {
722
+ method: "GET",
723
+ headers: {
724
+ [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
725
+ }
726
+ }).then((response2) => response2.json());
727
+ this.lastResponse = response;
728
+ onUpdate == null ? void 0 : onUpdate(response);
729
+ return response;
730
+ } catch (error) {
731
+ return null;
732
+ }
733
+ });
734
+ const initialResponse = yield checkStatus();
735
+ this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
736
+ this.activeKey = publicApiKey;
737
+ return initialResponse;
738
+ });
739
+ }
740
+ getLastResponse() {
741
+ return this.lastResponse;
742
+ }
743
+ stop() {
744
+ this.instanceCount--;
745
+ if (this.instanceCount === 0) {
746
+ if (this.intervalId) {
747
+ clearInterval(this.intervalId);
748
+ this.intervalId = null;
749
+ this.activeKey = null;
750
+ this.lastResponse = null;
751
+ }
752
+ }
753
+ }
754
+ };
755
+
756
+ // src/components/usage-banner.tsx
757
+ var import_shared4 = require("@copilotkit/shared");
701
758
  var import_jsx_runtime5 = require("react/jsx-runtime");
759
+ var defaultIcons = {
760
+ [import_shared4.Severity.Error]: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
761
+ "svg",
762
+ {
763
+ viewBox: "0 0 24 24",
764
+ width: "20",
765
+ height: "20",
766
+ stroke: "currentColor",
767
+ strokeWidth: "2",
768
+ fill: "none",
769
+ strokeLinecap: "round",
770
+ strokeLinejoin: "round",
771
+ children: [
772
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
773
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
774
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
775
+ ]
776
+ }
777
+ )
778
+ };
779
+ function UsageBanner({
780
+ severity = import_shared4.Severity.Error,
781
+ message = "",
782
+ icon,
783
+ actions
784
+ }) {
785
+ if (!message || !severity) {
786
+ return null;
787
+ }
788
+ const Icon = icon || defaultIcons[severity];
789
+ const bgColor = {
790
+ info: "#dbeafe",
791
+ warning: "#fef3c7",
792
+ error: "#fee2e2"
793
+ }[severity];
794
+ const textColor = {
795
+ info: "#1e40af",
796
+ warning: "#854d0e",
797
+ error: "#991b1b"
798
+ }[severity];
799
+ const iconColor = {
800
+ info: "#3b82f6",
801
+ warning: "#eab308",
802
+ error: "#ef4444"
803
+ }[severity];
804
+ const primaryButtonColor = {
805
+ info: "#3b82f6",
806
+ warning: "#eab308",
807
+ error: "#ef4444"
808
+ }[severity];
809
+ const primaryButtonHoverColor = {
810
+ info: "#2563eb",
811
+ warning: "#ca8a04",
812
+ error: "#dc2626"
813
+ }[severity];
814
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
815
+ "div",
816
+ {
817
+ style: {
818
+ position: "fixed",
819
+ bottom: "16px",
820
+ left: "50%",
821
+ transform: "translateX(-50%)",
822
+ maxWidth: "90%",
823
+ zIndex: 9999
824
+ },
825
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
826
+ "div",
827
+ {
828
+ style: {
829
+ display: "flex",
830
+ flexWrap: "wrap",
831
+ alignItems: "center",
832
+ gap: "12px",
833
+ borderRadius: "9999px",
834
+ border: "1px solid #e5e7eb",
835
+ backgroundColor: bgColor,
836
+ padding: "8px 16px",
837
+ boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)"
838
+ },
839
+ children: [
840
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { color: iconColor }, children: Icon }),
841
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
842
+ "span",
843
+ {
844
+ style: {
845
+ flex: 1,
846
+ fontSize: "14px",
847
+ fontWeight: 500,
848
+ color: textColor,
849
+ whiteSpace: "normal",
850
+ wordBreak: "break-word"
851
+ },
852
+ children: message
853
+ }
854
+ ),
855
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
856
+ "div",
857
+ {
858
+ style: {
859
+ display: "flex",
860
+ gap: "8px",
861
+ flexWrap: "wrap"
862
+ },
863
+ children: [
864
+ (actions == null ? void 0 : actions.secondary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
865
+ "button",
866
+ {
867
+ onClick: actions.secondary.onClick,
868
+ style: {
869
+ borderRadius: "9999px",
870
+ padding: "4px 12px",
871
+ fontSize: "14px",
872
+ fontWeight: 500,
873
+ color: textColor,
874
+ backgroundColor: "transparent",
875
+ border: "none",
876
+ cursor: "pointer",
877
+ transition: "background-color 0.2s"
878
+ },
879
+ onMouseOver: (e) => e.currentTarget.style.backgroundColor = "rgba(255,255,255,0.5)",
880
+ onMouseOut: (e) => e.currentTarget.style.backgroundColor = "transparent",
881
+ children: actions.secondary.label
882
+ }
883
+ ),
884
+ (actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
885
+ "button",
886
+ {
887
+ onClick: actions.primary.onClick,
888
+ style: {
889
+ borderRadius: "9999px",
890
+ padding: "4px 12px",
891
+ fontSize: "14px",
892
+ fontWeight: 500,
893
+ color: "#fff",
894
+ backgroundColor: primaryButtonColor,
895
+ border: "none",
896
+ cursor: "pointer",
897
+ transition: "background-color 0.2s"
898
+ },
899
+ onMouseOver: (e) => e.currentTarget.style.backgroundColor = primaryButtonHoverColor,
900
+ onMouseOut: (e) => e.currentTarget.style.backgroundColor = primaryButtonColor,
901
+ children: actions.primary.label
902
+ }
903
+ )
904
+ ]
905
+ }
906
+ )
907
+ ]
908
+ }
909
+ )
910
+ }
911
+ );
912
+ }
913
+ function renderCopilotKitUsage(error) {
914
+ switch (error.name) {
915
+ case import_shared4.ERROR_NAMES.CONFIGURATION_ERROR:
916
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UsageBanner, { severity: error.severity, message: error.message });
917
+ case import_shared4.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
918
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
919
+ UsageBanner,
920
+ {
921
+ severity: error.severity,
922
+ message: error.message,
923
+ actions: {
924
+ primary: {
925
+ label: "Sign In",
926
+ onClick: () => {
927
+ window.location.href = "https://cloud.copilotkit.ai";
928
+ }
929
+ }
930
+ }
931
+ }
932
+ );
933
+ case import_shared4.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
934
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
935
+ UsageBanner,
936
+ {
937
+ severity: error.severity,
938
+ message: error.message,
939
+ actions: {
940
+ primary: {
941
+ label: "Upgrade",
942
+ onClick: () => {
943
+ window.location.href = "https://copilotkit.ai/";
944
+ }
945
+ }
946
+ }
947
+ }
948
+ );
949
+ }
950
+ }
951
+
952
+ // src/components/error-boundary/error-boundary.tsx
953
+ var import_jsx_runtime6 = require("react/jsx-runtime");
954
+ var statusChecker = new StatusChecker();
702
955
  var CopilotErrorBoundary = class extends import_react9.default.Component {
703
956
  constructor(props) {
704
957
  super(props);
705
- this.state = { hasError: false };
958
+ this.state = {
959
+ hasError: false
960
+ };
706
961
  }
707
962
  static getDerivedStateFromError(error) {
708
963
  return { hasError: true, error };
709
964
  }
965
+ componentDidMount() {
966
+ if (this.props.publicApiKey) {
967
+ statusChecker.start(this.props.publicApiKey, (newStatus) => {
968
+ this.setState((prevState) => {
969
+ var _a;
970
+ if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
971
+ return { status: newStatus != null ? newStatus : void 0 };
972
+ }
973
+ return null;
974
+ });
975
+ });
976
+ }
977
+ }
978
+ componentWillUnmount() {
979
+ statusChecker.stop();
980
+ }
710
981
  componentDidCatch(error, errorInfo) {
711
982
  console.error("CopilotKit Error:", error, errorInfo);
712
983
  }
713
984
  render() {
714
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
985
+ var _a, _b;
986
+ if (this.state.hasError) {
987
+ if (this.state.error instanceof import_shared5.CopilotKitError) {
988
+ return renderCopilotKitUsage(this.state.error);
989
+ }
990
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
991
+ }
992
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
993
+ this.props.children,
994
+ this.props.showUsageBanner ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
995
+ UsageBanner,
996
+ {
997
+ severity: (_a = this.state.status) == null ? void 0 : _a.severity,
998
+ message: (_b = this.state.status) == null ? void 0 : _b.message
999
+ }
1000
+ ) : null
1001
+ ] });
715
1002
  }
716
1003
  };
717
1004
  function ErrorToast2({ error, children }) {
@@ -725,21 +1012,17 @@ function ErrorToast2({ error, children }) {
725
1012
  }
726
1013
 
727
1014
  // src/components/copilot-provider/copilotkit.tsx
728
- var import_jsx_runtime6 = require("react/jsx-runtime");
1015
+ var import_jsx_runtime7 = require("react/jsx-runtime");
729
1016
  function CopilotKit(_a) {
730
1017
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
731
1018
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
732
1019
  const enabled = shouldShowDevConsole(showDevConsole);
733
- 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 })) }) });
1020
+ 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 })) }) });
734
1021
  }
735
- function CopilotKitInternal(_a) {
736
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
737
- if (!props.runtimeUrl && !props.publicApiKey) {
738
- throw new Error(
739
- "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
740
- );
741
- }
742
- const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
1022
+ function CopilotKitInternal(cpkProps) {
1023
+ const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
1024
+ validateProps(cpkProps);
1025
+ const chatApiEndpoint = props.runtimeUrl || import_shared6.COPILOT_CLOUD_CHAT_URL;
743
1026
  const [actions, setActions] = (0, import_react10.useState)({});
744
1027
  const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
745
1028
  const chatComponentsCache = (0, import_react10.useRef)({
@@ -833,15 +1116,8 @@ ${nonDocumentStrings}`;
833
1116
  },
834
1117
  [removeDocument]
835
1118
  );
836
- if (!props.publicApiKey) {
837
- if (props.cloudRestrictToTopic) {
838
- throw new Error(
839
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
840
- );
841
- }
842
- }
843
1119
  const copilotApiConfig = (0, import_react10.useMemo)(() => {
844
- var _a2, _b2;
1120
+ var _a2, _b;
845
1121
  let cloud = void 0;
846
1122
  if (props.publicApiKey) {
847
1123
  cloud = {
@@ -850,7 +1126,7 @@ ${nonDocumentStrings}`;
850
1126
  restrictToTopic: {
851
1127
  enabled: props.cloudRestrictToTopic ? true : false,
852
1128
  validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
853
- invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
1129
+ invalidTopics: ((_b = props.cloudRestrictToTopic) == null ? void 0 : _b.invalidTopics) || []
854
1130
  }
855
1131
  }
856
1132
  }
@@ -887,7 +1163,7 @@ ${nonDocumentStrings}`;
887
1163
  }
888
1164
  return acc;
889
1165
  }, {});
890
- return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1166
+ return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
891
1167
  }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
892
1168
  const runtimeClient = useCopilotRuntimeClient({
893
1169
  url: copilotApiConfig.chatApiEndpoint,
@@ -935,7 +1211,7 @@ ${nonDocumentStrings}`;
935
1211
  };
936
1212
  }
937
1213
  const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
938
- const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared3.randomUUID)());
1214
+ const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared6.randomUUID)());
939
1215
  const setThreadId = (0, import_react10.useCallback)(
940
1216
  (value) => {
941
1217
  if (props.threadId) {
@@ -953,7 +1229,7 @@ ${nonDocumentStrings}`;
953
1229
  const [runId, setRunId] = (0, import_react10.useState)(null);
954
1230
  const chatAbortControllerRef = (0, import_react10.useRef)(null);
955
1231
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
956
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1232
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
957
1233
  CopilotContext.Provider,
958
1234
  {
959
1235
  value: {
@@ -995,19 +1271,19 @@ ${nonDocumentStrings}`;
995
1271
  setRunId,
996
1272
  chatAbortControllerRef,
997
1273
  availableAgents,
998
- authConfig: props.authConfig,
999
- authStates,
1000
- setAuthStates,
1274
+ authConfig_c: props.authConfig_c,
1275
+ authStates_c: authStates,
1276
+ setAuthStates_c: setAuthStates,
1001
1277
  extensions,
1002
1278
  setExtensions
1003
1279
  },
1004
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
1280
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
1005
1281
  }
1006
1282
  );
1007
1283
  }
1008
1284
  var defaultCopilotContextCategories = ["global"];
1009
1285
  function entryPointsToFunctionCallHandler(actions) {
1010
- return (_0) => __async(this, [_0], function* ({ messages, name, args }) {
1286
+ return (_0) => __async(this, [_0], function* ({ name, args }) {
1011
1287
  let actionsByFunctionName = {};
1012
1288
  for (let action2 of actions) {
1013
1289
  actionsByFunctionName[action2.name] = action2;
@@ -1031,6 +1307,20 @@ function entryPointsToFunctionCallHandler(actions) {
1031
1307
  return result;
1032
1308
  });
1033
1309
  }
1310
+ function formatFeatureName(featureName) {
1311
+ return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
1312
+ }
1313
+ function validateProps(props) {
1314
+ const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
1315
+ if (!props.runtimeUrl && !props.publicApiKey) {
1316
+ throw new import_shared6.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
1317
+ }
1318
+ if (cloudFeatures.length > 0 && !props.publicApiKey) {
1319
+ throw new import_shared6.MissingPublicApiKeyError(
1320
+ `Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
1321
+ );
1322
+ }
1323
+ }
1034
1324
  // Annotate the CommonJS export names for ESM import in node:
1035
1325
  0 && (module.exports = {
1036
1326
  CopilotKit,