@copilotkit/react-core 1.77.2 → 1.79.0

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.
@@ -1655,7 +1655,7 @@ function useRenderToolCall() {
1655
1655
 
1656
1656
  //#endregion
1657
1657
  //#region package.json
1658
- var version = "1.77.2";
1658
+ var version = "1.79.0";
1659
1659
 
1660
1660
  //#endregion
1661
1661
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -3415,8 +3415,9 @@ const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follo
3415
3415
  const DEFAULT_LEARNING = Object.freeze({});
3416
3416
  function toLearningConfig(learning) {
3417
3417
  if (learning === true) return DEFAULT_LEARNING;
3418
- if (learning === false) return void 0;
3419
- return learning;
3418
+ if (learning === false || learning === void 0) return void 0;
3419
+ const { autoStart: _autoStart, ...config } = learning;
3420
+ return config;
3420
3421
  }
3421
3422
  function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3422
3423
  const empty = (0, react.useMemo)(() => [], []);
@@ -3428,7 +3429,7 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3428
3429
  return value;
3429
3430
  }
3430
3431
  const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, messageFilter, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, showIntelligenceIndicator = true, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug, learning }) => {
3431
- const learningConfig = toLearningConfig(learning);
3432
+ const learningConfig = (0, react.useMemo)(() => toLearningConfig(learning), [learning]);
3432
3433
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3433
3434
  const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
3434
3435
  (0, react.useEffect)(() => {
@@ -3521,15 +3522,15 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3521
3522
  (0, react.useEffect)(() => {
3522
3523
  if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence tier. Provide a `publicLicenseKey` for production use — contact the CopilotKit team about licensing.");
3523
3524
  }, [hasSelfManagedAgents, resolvedPublicKey]);
3524
- const headers = typeof headersProp === "function" ? headersProp() : headersProp;
3525
- const mergedHeaders = (0, react.useMemo)(() => {
3526
- if (!resolvedPublicKey) return headers;
3527
- if (headers[HEADER_NAME]) return headers;
3528
- return {
3529
- ...headers,
3530
- [HEADER_NAME]: resolvedPublicKey
3531
- };
3532
- }, [headers, resolvedPublicKey]);
3525
+ const headersRef = (0, react.useRef)(headersProp);
3526
+ headersRef.current = headersProp;
3527
+ const isHeadersBuilder = typeof headersProp === "function";
3528
+ const stableHeadersBuilder = (0, react.useCallback)(() => {
3529
+ const current = headersRef.current;
3530
+ return typeof current === "function" ? current() : current;
3531
+ }, []);
3532
+ const headersInput = isHeadersBuilder ? stableHeadersBuilder : headersProp;
3533
+ const headersSource = (0, react.useMemo)(() => (0, _copilotkit_core.ɵwithHeaderDefaults)(headersInput, resolvedPublicKey ? { [HEADER_NAME]: resolvedPublicKey } : {}), [headersInput, resolvedPublicKey]);
3533
3534
  if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {
3534
3535
  const message = "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";
3535
3536
  if (process.env.NODE_ENV === "production") throw new Error(message);
@@ -3654,7 +3655,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3654
3655
  runtimeUrl: chatApiEndpoint,
3655
3656
  deferInitialConnection: true,
3656
3657
  runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
3657
- headers: mergedHeaders,
3658
+ headers: headersSource,
3658
3659
  credentials,
3659
3660
  messageFilter,
3660
3661
  properties,
@@ -3749,7 +3750,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3749
3750
  (0, react.useEffect)(() => {
3750
3751
  copilotkit.setRuntimeUrl(chatApiEndpoint);
3751
3752
  copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
3752
- copilotkit.setHeaders(mergedHeaders);
3753
+ copilotkit.setHeaders(headersSource);
3753
3754
  copilotkit.setCredentials(credentials);
3754
3755
  copilotkit.setProperties(a2uiCatalogProvided ? {
3755
3756
  ...properties,
@@ -3761,7 +3762,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3761
3762
  }, [
3762
3763
  copilotkit,
3763
3764
  chatApiEndpoint,
3764
- mergedHeaders,
3765
+ headersSource,
3765
3766
  credentials,
3766
3767
  properties,
3767
3768
  a2uiCatalogProvided,
@@ -3770,15 +3771,25 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3770
3771
  debug
3771
3772
  ]);
3772
3773
  const learningEnabled = learningConfig !== void 0;
3773
- const generatesTrajectoryId = learning === true;
3774
- const suppliedTrajectoryId = learningConfig?.trajectoryId;
3774
+ const autoStart = learningEnabled && (typeof learning !== "object" || learning.autoStart !== false);
3775
+ const suppliedTrajectoryId = autoStart ? learningConfig?.trajectoryId : void 0;
3776
+ const generatesTrajectoryId = autoStart && suppliedTrajectoryId === void 0;
3775
3777
  const learningContainerIdsRef = (0, react.useRef)(learningConfig?.learningContainerIds);
3776
3778
  const generatedTrajectoryIdRef = (0, react.useRef)(void 0);
3777
3779
  (0, react.useEffect)(() => {
3778
3780
  copilotkit.setLearningConfig(learningConfig);
3779
3781
  learningContainerIdsRef.current = learningConfig?.learningContainerIds;
3780
- if (learningConfig?.sink === void 0 && learningConfig?.trajectoryId === void 0 && learningConfig?.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
3781
- }, [copilotkit, learningConfig]);
3782
+ if (learningConfig?.sink === void 0 && !autoStart && learningConfig?.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
3783
+ }, [
3784
+ copilotkit,
3785
+ learningConfig,
3786
+ autoStart
3787
+ ]);
3788
+ const ignoresTrajectoryId = !autoStart && learningConfig?.trajectoryId !== void 0;
3789
+ (0, react.useEffect)(() => {
3790
+ if (!ignoresTrajectoryId) return;
3791
+ console.warn("[CopilotKit] learning.trajectoryId is ignored when autoStart is false; pass the ID to startTrajectory() instead.");
3792
+ }, [ignoresTrajectoryId]);
3782
3793
  (0, react.useEffect)(() => {
3783
3794
  if (!generatesTrajectoryId) generatedTrajectoryIdRef.current = void 0;
3784
3795
  if (!learningEnabled) return;
@@ -3873,17 +3884,17 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3873
3884
  const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== void 0 && runtimeEntitlements.status !== "ready";
3874
3885
  const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
3875
3886
  const runtimeEntitlementRetryInProgress = retryableRuntimeEntitlementFailure && runtimeEntitlementRetryPending && !hasLegacyRuntimeEntitlementFallback;
3876
- const runtimeEntitlementFailureSettled = hasNonReadyRuntimeEntitlement && !runtimeEntitlementRetryInProgress && !hasLegacyRuntimeEntitlementFallback;
3887
+ const terminalRuntimeEntitlementFailure = hasNonReadyRuntimeEntitlement && !retryableRuntimeEntitlementFailure && !hasLegacyRuntimeEntitlementFallback;
3877
3888
  const licenseContextValue = (0, react.useMemo)(() => {
3878
3889
  const runtimeLicenseContext = (0, _copilotkit_shared.createLicenseContextValue)(runtimeEntitlementRetryInProgress ? void 0 : runtimeLicenseStatus, runtimeEntitlements);
3879
- if (!runtimeEntitlementFailureSettled) return runtimeLicenseContext;
3890
+ if (!terminalRuntimeEntitlementFailure) return runtimeLicenseContext;
3880
3891
  return {
3881
3892
  ...runtimeLicenseContext,
3882
3893
  checkFeature: () => false,
3883
3894
  getLimit: () => null
3884
3895
  };
3885
3896
  }, [
3886
- runtimeEntitlementFailureSettled,
3897
+ terminalRuntimeEntitlementFailure,
3887
3898
  runtimeEntitlementRetryInProgress,
3888
3899
  runtimeEntitlements,
3889
3900
  runtimeLicenseStatus
@@ -5375,9 +5386,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5375
5386
  const hasMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectHasNextPage);
5376
5387
  const isFetchingMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsFetchingNextPage);
5377
5388
  const isMutating = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsMutating);
5378
- const headersKey = (0, react.useMemo)(() => {
5379
- return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
5380
- }, [copilotkit.headers]);
5389
+ const headersKey = copilotkit.ɵheadersGeneration;
5381
5390
  const runtimeStatus = copilotkit.runtimeConnectionStatus;
5382
5391
  const threadListEndpointSupported = copilotkit.threadEndpoints?.list !== false;
5383
5392
  const threadMutationsSupported = copilotkit.threadEndpoints?.mutations !== false;
@@ -5442,7 +5451,6 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5442
5451
  }
5443
5452
  const context = {
5444
5453
  runtimeUrl: copilotkit.runtimeUrl,
5445
- headers: { ...copilotkit.headers },
5446
5454
  wsUrl: copilotkit.intelligence?.wsUrl,
5447
5455
  agentId,
5448
5456
  includeArchived,
@@ -5570,7 +5578,9 @@ function useMemories() {
5570
5578
  *
5571
5579
  * The function uses the same transport as `useLearnFromUserAction`:
5572
5580
  * - `runtimeUrl` from `copilotkit.runtimeUrl` (BFF proxies to the platform)
5573
- * - `headers` from `copilotkit.headers` (customer auth forwarded to BFF)
5581
+ * - `fetch: copilotkit.ɵruntimeFetch`, which adds the current core headers at
5582
+ * send time (#1937); `headers` here is only for extra request-specific
5583
+ * headers on top of that
5574
5584
  * - `clientEventId` auto-generated via `randomUUID()` when omitted
5575
5585
  * - `userId` is resolved server-side by the runtime; the client never sends it
5576
5586
  * - Errors propagate to the caller (fire-and-propagate, not fire-and-forget)
@@ -5662,7 +5672,7 @@ function useLearnFromUserAction() {
5662
5672
  return recordAnnotation({
5663
5673
  fetch: copilotkit.ɵruntimeFetch,
5664
5674
  runtimeUrl,
5665
- headers: copilotkit.headers ?? {},
5675
+ headers: {},
5666
5676
  type: "user_action",
5667
5677
  payload: Object.keys(payload).length > 0 ? payload : void 0,
5668
5678
  threadId: input.threadId,
@@ -5990,16 +6000,13 @@ function useLearningContainers({ threadId, learningContainers }) {
5990
6000
  /** Guards the missing-runtimeUrl warning so it fires at most once per hook instance. */
5991
6001
  const warnedMissingUrlRef = (0, react.useRef)(false);
5992
6002
  const runtimeUrlRef = (0, react.useRef)(copilotkit.runtimeUrl);
5993
- const headersRef = (0, react.useRef)(copilotkit.headers ?? {});
5994
6003
  const runtimeFetchRef = (0, react.useRef)(copilotkit.ɵruntimeFetch);
5995
6004
  runtimeUrlRef.current = copilotkit.runtimeUrl;
5996
- headersRef.current = copilotkit.headers ?? {};
5997
6005
  runtimeFetchRef.current = copilotkit.ɵruntimeFetch;
5998
6006
  const key = JSON.stringify(learningContainers);
5999
6007
  const defaultKey = JSON.stringify(DEFAULT_CONTAINERS);
6000
6008
  (0, react.useEffect)(() => {
6001
6009
  const runtimeUrl = copilotkit.runtimeUrl;
6002
- const headers = copilotkit.headers ?? {};
6003
6010
  /**
6004
6011
  * Fire-and-forget emit; errors must not surface in render.
6005
6012
  * Failures are logged as warnings so they are diagnosable without
@@ -6016,7 +6023,7 @@ function useLearningContainers({ threadId, learningContainers }) {
6016
6023
  recordAnnotation({
6017
6024
  fetch: copilotkit.ɵruntimeFetch,
6018
6025
  runtimeUrl,
6019
- headers,
6026
+ headers: {},
6020
6027
  type: "set_learning_containers",
6021
6028
  payload: { containers },
6022
6029
  threadId
@@ -6040,11 +6047,10 @@ function useLearningContainers({ threadId, learningContainers }) {
6040
6047
  const capturedThreadId = threadId;
6041
6048
  return () => {
6042
6049
  const capturedRuntimeUrl = runtimeUrlRef.current;
6043
- const capturedHeaders = headersRef.current;
6044
6050
  if (capturedRuntimeUrl) recordAnnotation({
6045
6051
  fetch: runtimeFetchRef.current,
6046
6052
  runtimeUrl: capturedRuntimeUrl,
6047
- headers: capturedHeaders,
6053
+ headers: {},
6048
6054
  type: "set_learning_containers",
6049
6055
  payload: { containers: DEFAULT_CONTAINERS },
6050
6056
  threadId: capturedThreadId
@@ -8850,7 +8856,7 @@ async function transcribeAudio(core, audioBlob, filename = "recording.webm") {
8850
8856
  message: "Runtime URL is not configured",
8851
8857
  retryable: false
8852
8858
  });
8853
- const headers = { ...core.headers };
8859
+ const headers = { ...await core.resolveHeaders() };
8854
8860
  let response;
8855
8861
  try {
8856
8862
  if (core.runtimeTransport === "single") {
@@ -9262,7 +9268,6 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9262
9268
  threadStore.start();
9263
9269
  const context = copilotkit.runtimeUrl ? {
9264
9270
  runtimeUrl: copilotkit.runtimeUrl,
9265
- headers: { ...copilotkit.headers },
9266
9271
  wsUrl: copilotkit.intelligence?.wsUrl,
9267
9272
  agentId: resolvedAgentId
9268
9273
  } : null;
@@ -9358,7 +9363,7 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9358
9363
  hasNativeIntelligenceRunActivity,
9359
9364
  copilotkit.runtimeConnectionStatus,
9360
9365
  copilotkit.runtimeUrl,
9361
- copilotkit.headers,
9366
+ copilotkit.ɵheadersGeneration,
9362
9367
  copilotkit.intelligence?.wsUrl,
9363
9368
  copilotkit.threadEndpoints?.realtimeMetadata,
9364
9369
  standaloneRunActivityStore,
@@ -12349,6 +12354,16 @@ function CopilotListeners() {
12349
12354
 
12350
12355
  //#endregion
12351
12356
  //#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
12357
+ /**
12358
+ * Drops `null`/`undefined` entries so a `CopilotKitHeadersSource` record (or
12359
+ * a builder's resolved record) matches `CopilotApiConfig.headers`'s
12360
+ * `Record<string, string>` shape. Mirrors core's own (internal-only)
12361
+ * `normalizeHeaders`.
12362
+ */
12363
+ function normalizeV1Headers(headers) {
12364
+ if (!headers) return {};
12365
+ return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
12366
+ }
12352
12367
  function CopilotKit({ children, ...props }) {
12353
12368
  const enabled = shouldShowDevConsole(props.showDevConsole);
12354
12369
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
@@ -12428,6 +12443,13 @@ function CopilotKitInternal(cpkProps) {
12428
12443
  * This will throw an error if the props are invalid.
12429
12444
  */
12430
12445
  validateProps(cpkProps);
12446
+ const headersPropRef = (0, react.useRef)(props.headers);
12447
+ headersPropRef.current = props.headers;
12448
+ const headersBuilderStateRef = (0, react.useRef)({
12449
+ fn: void 0,
12450
+ isAsync: false
12451
+ });
12452
+ const warnedAsyncHeadersRef = (0, react.useRef)(false);
12431
12453
  const publicApiKey = props.publicLicenseKey || props.publicApiKey;
12432
12454
  const chatApiEndpoint = props.runtimeUrl || _copilotkit_shared.COPILOT_CLOUD_CHAT_URL;
12433
12455
  const [actions, setActions] = (0, react.useState)({});
@@ -12495,19 +12517,46 @@ function CopilotKitInternal(cpkProps) {
12495
12517
  validTopics: props.guardrails_c?.validTopics || [],
12496
12518
  invalidTopics: props.guardrails_c?.invalidTopics || []
12497
12519
  } } } };
12498
- return {
12520
+ const config = {
12499
12521
  publicApiKey,
12500
12522
  ...cloud ? { cloud } : {},
12501
12523
  chatApiEndpoint,
12502
- headers: typeof props.headers === "function" ? props.headers() : props.headers || {},
12503
12524
  properties: props.properties || {},
12504
12525
  transcribeAudioUrl: props.transcribeAudioUrl,
12505
12526
  textToSpeechUrl: props.textToSpeechUrl,
12506
12527
  credentials: props.credentials
12507
12528
  };
12529
+ Object.defineProperty(config, "headers", {
12530
+ enumerable: true,
12531
+ configurable: true,
12532
+ get() {
12533
+ const source = headersPropRef.current;
12534
+ if (typeof source !== "function") return normalizeV1Headers(source);
12535
+ const state = headersBuilderStateRef.current;
12536
+ if (state.fn === source && state.isAsync) return {};
12537
+ const result = source();
12538
+ if (typeof result === "object" && result !== null && typeof result.then === "function") {
12539
+ headersBuilderStateRef.current = {
12540
+ fn: source,
12541
+ isAsync: true
12542
+ };
12543
+ result.then(void 0, () => {});
12544
+ if (process.env.NODE_ENV !== "production" && !warnedAsyncHeadersRef.current) {
12545
+ warnedAsyncHeadersRef.current = true;
12546
+ console.warn("[CopilotKit] An async `headers` builder is not supported by the v1 CopilotTask / GraphQL path; its headers are not sent there.");
12547
+ }
12548
+ return {};
12549
+ }
12550
+ headersBuilderStateRef.current = {
12551
+ fn: source,
12552
+ isAsync: false
12553
+ };
12554
+ return normalizeV1Headers(result);
12555
+ }
12556
+ });
12557
+ return config;
12508
12558
  }, [
12509
12559
  publicApiKey,
12510
- props.headers,
12511
12560
  props.properties,
12512
12561
  props.transcribeAudioUrl,
12513
12562
  props.textToSpeechUrl,
@@ -12515,27 +12564,6 @@ function CopilotKitInternal(cpkProps) {
12515
12564
  props.cloudRestrictToTopic,
12516
12565
  props.guardrails_c
12517
12566
  ]);
12518
- (0, react.useMemo)(() => {
12519
- const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
12520
- if (state.status === "authenticated" && state.authHeaders) return {
12521
- ...acc,
12522
- ...Object.entries(state.authHeaders).reduce((headers, [key, value]) => ({
12523
- ...headers,
12524
- [key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
12525
- }), {})
12526
- };
12527
- return acc;
12528
- }, {});
12529
- return {
12530
- ...copilotApiConfig.headers,
12531
- ...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
12532
- ...authHeaders
12533
- };
12534
- }, [
12535
- copilotApiConfig.headers,
12536
- copilotApiConfig.publicApiKey,
12537
- authStates
12538
- ]);
12539
12567
  const [internalErrorHandlers, _setInternalErrorHandler] = (0, react.useState)({});
12540
12568
  const setInternalErrorHandler = (0, react.useCallback)((handler) => {
12541
12569
  _setInternalErrorHandler((prev) => ({
@@ -13366,4 +13394,4 @@ Object.defineProperty(exports, 'useToast', {
13366
13394
  return useToast;
13367
13395
  }
13368
13396
  });
13369
- //# sourceMappingURL=copilotkit-D7_J5Hs_.cjs.map
13397
+ //# sourceMappingURL=copilotkit-DjrKQjfL.cjs.map