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