@copilotkitnext/react 0.0.30 → 0.0.32

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
@@ -1510,6 +1510,8 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
1510
1510
 
1511
1511
  // src/providers/CopilotKitProvider.tsx
1512
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";
1513
1515
  var CopilotKitContext = (0, import_react6.createContext)({
1514
1516
  copilotkit: null
1515
1517
  });
@@ -1528,6 +1530,8 @@ var CopilotKitProvider = ({
1528
1530
  children,
1529
1531
  runtimeUrl,
1530
1532
  headers = {},
1533
+ publicApiKey,
1534
+ publicLicenseKey,
1531
1535
  properties = {},
1532
1536
  agents__unsafe_dev_only: agents = {},
1533
1537
  renderToolCalls,
@@ -1577,6 +1581,25 @@ var CopilotKitProvider = ({
1577
1581
  renderActivityMessages,
1578
1582
  "renderActivityMessages must be a stable array."
1579
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);
1580
1603
  const frontendToolsList = useStableArrayProp(
1581
1604
  frontendTools,
1582
1605
  "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
@@ -1639,9 +1662,9 @@ var CopilotKitProvider = ({
1639
1662
  }, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
1640
1663
  const copilotkit = (0, import_react6.useMemo)(() => {
1641
1664
  const copilotkit2 = new CopilotKitCoreReact({
1642
- runtimeUrl,
1665
+ runtimeUrl: chatApiEndpoint,
1643
1666
  runtimeTransport: useSingleEndpoint ? "single" : "rest",
1644
- headers,
1667
+ headers: mergedHeaders,
1645
1668
  properties,
1646
1669
  agents__unsafe_dev_only: agents,
1647
1670
  tools: allTools,
@@ -1663,12 +1686,12 @@ var CopilotKitProvider = ({
1663
1686
  };
1664
1687
  }, [copilotkit]);
1665
1688
  (0, import_react6.useEffect)(() => {
1666
- copilotkit.setRuntimeUrl(runtimeUrl);
1689
+ copilotkit.setRuntimeUrl(chatApiEndpoint);
1667
1690
  copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
1668
- copilotkit.setHeaders(headers);
1691
+ copilotkit.setHeaders(mergedHeaders);
1669
1692
  copilotkit.setProperties(properties);
1670
1693
  copilotkit.setAgents__unsafe_dev_only(agents);
1671
- }, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
1694
+ }, [chatApiEndpoint, mergedHeaders, properties, agents, useSingleEndpoint]);
1672
1695
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1673
1696
  CopilotKitContext.Provider,
1674
1697
  {