@copilotkitnext/react 0.0.29 → 0.0.31

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.
package/dist/index.d.mts CHANGED
@@ -632,6 +632,14 @@ interface CopilotKitProviderProps {
632
632
  children: ReactNode;
633
633
  runtimeUrl?: string;
634
634
  headers?: Record<string, string>;
635
+ /**
636
+ * The Copilot Cloud public API key.
637
+ */
638
+ publicApiKey?: string;
639
+ /**
640
+ * Alias for `publicApiKey`
641
+ **/
642
+ publicLicenseKey?: string;
635
643
  properties?: Record<string, unknown>;
636
644
  useSingleEndpoint?: boolean;
637
645
  agents__unsafe_dev_only?: Record<string, AbstractAgent>;
package/dist/index.d.ts CHANGED
@@ -632,6 +632,14 @@ interface CopilotKitProviderProps {
632
632
  children: ReactNode;
633
633
  runtimeUrl?: string;
634
634
  headers?: Record<string, string>;
635
+ /**
636
+ * The Copilot Cloud public API key.
637
+ */
638
+ publicApiKey?: string;
639
+ /**
640
+ * Alias for `publicApiKey`
641
+ **/
642
+ publicLicenseKey?: string;
635
643
  properties?: Record<string, unknown>;
636
644
  useSingleEndpoint?: boolean;
637
645
  agents__unsafe_dev_only?: Record<string, AbstractAgent>;
package/dist/index.js CHANGED
@@ -1484,26 +1484,34 @@ var CopilotKitCoreReact = class extends import_core.CopilotKitCore {
1484
1484
  var React4 = __toESM(require("react"));
1485
1485
  var import_react5 = require("@lit-labs/react");
1486
1486
  var import_jsx_runtime7 = require("react/jsx-runtime");
1487
- var CopilotKitInspectorBase = React4.lazy(() => {
1488
- if (typeof window === "undefined") {
1489
- const NullComponent = () => null;
1490
- return Promise.resolve({ default: NullComponent });
1491
- }
1492
- return import("@copilotkitnext/web-inspector").then((mod) => {
1493
- mod.defineWebInspector?.();
1494
- const Component = (0, import_react5.createComponent)({
1495
- tagName: mod.WEB_INSPECTOR_TAG,
1496
- elementClass: mod.WebInspectorElement,
1497
- react: React4
1487
+ var CopilotKitInspector = ({ core, ...rest }) => {
1488
+ const [InspectorComponent, setInspectorComponent] = React4.useState(null);
1489
+ React4.useEffect(() => {
1490
+ let mounted = true;
1491
+ import("@copilotkitnext/web-inspector").then((mod) => {
1492
+ mod.defineWebInspector?.();
1493
+ const Component = (0, import_react5.createComponent)({
1494
+ tagName: mod.WEB_INSPECTOR_TAG,
1495
+ elementClass: mod.WebInspectorElement,
1496
+ react: React4
1497
+ });
1498
+ if (mounted) {
1499
+ setInspectorComponent(() => Component);
1500
+ }
1498
1501
  });
1499
- return { default: Component };
1500
- });
1501
- });
1502
- var CopilotKitInspector = ({ core, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(React4.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotKitInspectorBase, { ...rest, core: core ?? null }) });
1502
+ return () => {
1503
+ mounted = false;
1504
+ };
1505
+ }, []);
1506
+ if (!InspectorComponent) return null;
1507
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InspectorComponent, { ...rest, core: core ?? null });
1508
+ };
1503
1509
  CopilotKitInspector.displayName = "CopilotKitInspector";
1504
1510
 
1505
1511
  // src/providers/CopilotKitProvider.tsx
1506
1512
  var import_jsx_runtime8 = require("react/jsx-runtime");
1513
+ var HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
1514
+ var COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
1507
1515
  var CopilotKitContext = (0, import_react6.createContext)({
1508
1516
  copilotkit: null
1509
1517
  });
@@ -1522,6 +1530,8 @@ var CopilotKitProvider = ({
1522
1530
  children,
1523
1531
  runtimeUrl,
1524
1532
  headers = {},
1533
+ publicApiKey,
1534
+ publicLicenseKey,
1525
1535
  properties = {},
1526
1536
  agents__unsafe_dev_only: agents = {},
1527
1537
  renderToolCalls,
@@ -1571,6 +1581,25 @@ var CopilotKitProvider = ({
1571
1581
  renderActivityMessages,
1572
1582
  "renderActivityMessages must be a stable array."
1573
1583
  );
1584
+ const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
1585
+ const hasLocalAgents = agents && Object.keys(agents).length > 0;
1586
+ const mergedHeaders = (0, import_react6.useMemo)(() => {
1587
+ if (!resolvedPublicKey) return headers;
1588
+ if (headers[HEADER_NAME]) return headers;
1589
+ return {
1590
+ ...headers,
1591
+ [HEADER_NAME]: resolvedPublicKey
1592
+ };
1593
+ }, [headers, resolvedPublicKey]);
1594
+ if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {
1595
+ const message = "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";
1596
+ if (process.env.NODE_ENV === "production") {
1597
+ throw new Error(message);
1598
+ } else {
1599
+ console.warn(message);
1600
+ }
1601
+ }
1602
+ const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL : void 0);
1574
1603
  const frontendToolsList = useStableArrayProp(
1575
1604
  frontendTools,
1576
1605
  "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
@@ -1633,9 +1662,9 @@ var CopilotKitProvider = ({
1633
1662
  }, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
1634
1663
  const copilotkit = (0, import_react6.useMemo)(() => {
1635
1664
  const copilotkit2 = new CopilotKitCoreReact({
1636
- runtimeUrl,
1665
+ runtimeUrl: chatApiEndpoint,
1637
1666
  runtimeTransport: useSingleEndpoint ? "single" : "rest",
1638
- headers,
1667
+ headers: mergedHeaders,
1639
1668
  properties,
1640
1669
  agents__unsafe_dev_only: agents,
1641
1670
  tools: allTools,
@@ -1657,12 +1686,12 @@ var CopilotKitProvider = ({
1657
1686
  };
1658
1687
  }, [copilotkit]);
1659
1688
  (0, import_react6.useEffect)(() => {
1660
- copilotkit.setRuntimeUrl(runtimeUrl);
1689
+ copilotkit.setRuntimeUrl(chatApiEndpoint);
1661
1690
  copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
1662
- copilotkit.setHeaders(headers);
1691
+ copilotkit.setHeaders(mergedHeaders);
1663
1692
  copilotkit.setProperties(properties);
1664
1693
  copilotkit.setAgents__unsafe_dev_only(agents);
1665
- }, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
1694
+ }, [chatApiEndpoint, mergedHeaders, properties, agents, useSingleEndpoint]);
1666
1695
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1667
1696
  CopilotKitContext.Provider,
1668
1697
  {