@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.mjs CHANGED
@@ -1382,15 +1382,7 @@ import React6, { useCallback as useCallback2, useEffect as useEffect5, useMemo a
1382
1382
  import { ToolCallStatus } from "@copilotkitnext/core";
1383
1383
 
1384
1384
  // src/providers/CopilotKitProvider.tsx
1385
- import {
1386
- createContext as createContext2,
1387
- useContext as useContext2,
1388
- useMemo as useMemo3,
1389
- useEffect as useEffect4,
1390
- useReducer,
1391
- useRef as useRef3,
1392
- useState as useState4
1393
- } from "react";
1385
+ import { createContext as createContext2, useContext as useContext2, useMemo as useMemo3, useEffect as useEffect4, useReducer, useRef as useRef3, useState as useState4 } from "react";
1394
1386
  import { z } from "zod";
1395
1387
 
1396
1388
  // src/lib/react-core.ts
@@ -1465,6 +1457,8 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
1465
1457
 
1466
1458
  // src/providers/CopilotKitProvider.tsx
1467
1459
  import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
1460
+ var HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
1461
+ var COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
1468
1462
  var CopilotKitContext = createContext2({
1469
1463
  copilotkit: null
1470
1464
  });
@@ -1483,6 +1477,8 @@ var CopilotKitProvider = ({
1483
1477
  children,
1484
1478
  runtimeUrl,
1485
1479
  headers = {},
1480
+ publicApiKey,
1481
+ publicLicenseKey,
1486
1482
  properties = {},
1487
1483
  agents__unsafe_dev_only: agents = {},
1488
1484
  renderToolCalls,
@@ -1532,6 +1528,25 @@ var CopilotKitProvider = ({
1532
1528
  renderActivityMessages,
1533
1529
  "renderActivityMessages must be a stable array."
1534
1530
  );
1531
+ const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
1532
+ const hasLocalAgents = agents && Object.keys(agents).length > 0;
1533
+ const mergedHeaders = useMemo3(() => {
1534
+ if (!resolvedPublicKey) return headers;
1535
+ if (headers[HEADER_NAME]) return headers;
1536
+ return {
1537
+ ...headers,
1538
+ [HEADER_NAME]: resolvedPublicKey
1539
+ };
1540
+ }, [headers, resolvedPublicKey]);
1541
+ if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {
1542
+ const message = "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";
1543
+ if (process.env.NODE_ENV === "production") {
1544
+ throw new Error(message);
1545
+ } else {
1546
+ console.warn(message);
1547
+ }
1548
+ }
1549
+ const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL : void 0);
1535
1550
  const frontendToolsList = useStableArrayProp(
1536
1551
  frontendTools,
1537
1552
  "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
@@ -1594,9 +1609,9 @@ var CopilotKitProvider = ({
1594
1609
  }, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
1595
1610
  const copilotkit = useMemo3(() => {
1596
1611
  const copilotkit2 = new CopilotKitCoreReact({
1597
- runtimeUrl,
1612
+ runtimeUrl: chatApiEndpoint,
1598
1613
  runtimeTransport: useSingleEndpoint ? "single" : "rest",
1599
- headers,
1614
+ headers: mergedHeaders,
1600
1615
  properties,
1601
1616
  agents__unsafe_dev_only: agents,
1602
1617
  tools: allTools,
@@ -1618,12 +1633,12 @@ var CopilotKitProvider = ({
1618
1633
  };
1619
1634
  }, [copilotkit]);
1620
1635
  useEffect4(() => {
1621
- copilotkit.setRuntimeUrl(runtimeUrl);
1636
+ copilotkit.setRuntimeUrl(chatApiEndpoint);
1622
1637
  copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
1623
- copilotkit.setHeaders(headers);
1638
+ copilotkit.setHeaders(mergedHeaders);
1624
1639
  copilotkit.setProperties(properties);
1625
1640
  copilotkit.setAgents__unsafe_dev_only(agents);
1626
- }, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
1641
+ }, [chatApiEndpoint, mergedHeaders, properties, agents, useSingleEndpoint]);
1627
1642
  return /* @__PURE__ */ jsxs4(
1628
1643
  CopilotKitContext.Provider,
1629
1644
  {