@copilotkit/react-core 1.78.0 → 1.79.1-canary.1792034358

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.
@@ -1766,7 +1766,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1766
1766
 
1767
1767
  //#endregion
1768
1768
  //#region package.json
1769
- var version = "1.78.0";
1769
+ var version = "1.79.1-canary.1792034358";
1770
1770
 
1771
1771
  //#endregion
1772
1772
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -3537,15 +3537,15 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
3537
3537
  (0, react.useEffect)(() => {
3538
3538
  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.");
3539
3539
  }, [hasSelfManagedAgents, resolvedPublicKey]);
3540
- const headers = typeof headersProp === "function" ? headersProp() : headersProp;
3541
- const mergedHeaders = (0, react.useMemo)(() => {
3542
- if (!resolvedPublicKey) return headers;
3543
- if (headers[HEADER_NAME]) return headers;
3544
- return {
3545
- ...headers,
3546
- [HEADER_NAME]: resolvedPublicKey
3547
- };
3548
- }, [headers, resolvedPublicKey]);
3540
+ const headersRef = (0, react.useRef)(headersProp);
3541
+ headersRef.current = headersProp;
3542
+ const isHeadersBuilder = typeof headersProp === "function";
3543
+ const stableHeadersBuilder = (0, react.useCallback)(() => {
3544
+ const current = headersRef.current;
3545
+ return typeof current === "function" ? current() : current;
3546
+ }, []);
3547
+ const headersInput = isHeadersBuilder ? stableHeadersBuilder : headersProp;
3548
+ const headersSource = (0, react.useMemo)(() => (0, _copilotkit_core.ɵwithHeaderDefaults)(headersInput, resolvedPublicKey ? { [HEADER_NAME]: resolvedPublicKey } : {}), [headersInput, resolvedPublicKey]);
3549
3549
  if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {
3550
3550
  const message = "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";
3551
3551
  if (process.env.NODE_ENV === "production") throw new Error(message);
@@ -3670,7 +3670,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
3670
3670
  runtimeUrl: chatApiEndpoint,
3671
3671
  deferInitialConnection: true,
3672
3672
  runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
3673
- headers: mergedHeaders,
3673
+ headers: headersSource,
3674
3674
  credentials,
3675
3675
  messageFilter,
3676
3676
  properties,
@@ -3765,7 +3765,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
3765
3765
  (0, react.useEffect)(() => {
3766
3766
  copilotkit.setRuntimeUrl(chatApiEndpoint);
3767
3767
  copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
3768
- copilotkit.setHeaders(mergedHeaders);
3768
+ copilotkit.setHeaders(headersSource);
3769
3769
  copilotkit.setCredentials(credentials);
3770
3770
  copilotkit.setProperties(a2uiCatalogProvided ? {
3771
3771
  ...properties,
@@ -3777,7 +3777,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
3777
3777
  }, [
3778
3778
  copilotkit,
3779
3779
  chatApiEndpoint,
3780
- mergedHeaders,
3780
+ headersSource,
3781
3781
  credentials,
3782
3782
  properties,
3783
3783
  a2uiCatalogProvided,
@@ -3794,7 +3794,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
3794
3794
  (0, react.useEffect)(() => {
3795
3795
  copilotkit.setLearningConfig(learningConfig);
3796
3796
  learningContainerIdsRef.current = learningConfig?.learningContainerIds;
3797
- 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.");
3797
+ if (learningConfig?.sink === void 0 && !autoStart && learningConfig?.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture ignores it; assign Learning Spaces on the server with getTrajectoryLearningContainerIds on CopilotKitIntelligence, and remove learningContainerIds from the capture options.");
3798
3798
  }, [
3799
3799
  copilotkit,
3800
3800
  learningConfig,
@@ -5401,9 +5401,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
5401
5401
  const hasMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectHasNextPage);
5402
5402
  const isFetchingMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsFetchingNextPage);
5403
5403
  const isMutating = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsMutating);
5404
- const headersKey = (0, react.useMemo)(() => {
5405
- return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
5406
- }, [copilotkit.headers]);
5404
+ const headersKey = copilotkit.ɵheadersGeneration;
5407
5405
  const runtimeStatus = copilotkit.runtimeConnectionStatus;
5408
5406
  const threadListEndpointSupported = copilotkit.threadEndpoints?.list !== false;
5409
5407
  const threadMutationsSupported = copilotkit.threadEndpoints?.mutations !== false;
@@ -5468,7 +5466,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
5468
5466
  }
5469
5467
  const context = {
5470
5468
  runtimeUrl: copilotkit.runtimeUrl,
5471
- headers: { ...copilotkit.headers },
5472
5469
  wsUrl: copilotkit.intelligence?.wsUrl,
5473
5470
  agentId,
5474
5471
  includeArchived,
@@ -5596,7 +5593,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
5596
5593
  *
5597
5594
  * The function uses the same transport as `useLearnFromUserAction`:
5598
5595
  * - `runtimeUrl` from `copilotkit.runtimeUrl` (BFF proxies to the platform)
5599
- * - `headers` from `copilotkit.headers` (customer auth forwarded to BFF)
5596
+ * - `fetch: copilotkit.ɵruntimeFetch`, which adds the current core headers at
5597
+ * send time (#1937); `headers` here is only for extra request-specific
5598
+ * headers on top of that
5600
5599
  * - `clientEventId` auto-generated via `randomUUID()` when omitted
5601
5600
  * - `userId` is resolved server-side by the runtime; the client never sends it
5602
5601
  * - Errors propagate to the caller (fire-and-propagate, not fire-and-forget)
@@ -5688,7 +5687,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
5688
5687
  return recordAnnotation({
5689
5688
  fetch: copilotkit.ɵruntimeFetch,
5690
5689
  runtimeUrl,
5691
- headers: copilotkit.headers ?? {},
5690
+ headers: {},
5692
5691
  type: "user_action",
5693
5692
  payload: Object.keys(payload).length > 0 ? payload : void 0,
5694
5693
  threadId: input.threadId,
@@ -6016,16 +6015,13 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
6016
6015
  /** Guards the missing-runtimeUrl warning so it fires at most once per hook instance. */
6017
6016
  const warnedMissingUrlRef = (0, react.useRef)(false);
6018
6017
  const runtimeUrlRef = (0, react.useRef)(copilotkit.runtimeUrl);
6019
- const headersRef = (0, react.useRef)(copilotkit.headers ?? {});
6020
6018
  const runtimeFetchRef = (0, react.useRef)(copilotkit.ɵruntimeFetch);
6021
6019
  runtimeUrlRef.current = copilotkit.runtimeUrl;
6022
- headersRef.current = copilotkit.headers ?? {};
6023
6020
  runtimeFetchRef.current = copilotkit.ɵruntimeFetch;
6024
6021
  const key = JSON.stringify(learningContainers);
6025
6022
  const defaultKey = JSON.stringify(DEFAULT_CONTAINERS);
6026
6023
  (0, react.useEffect)(() => {
6027
6024
  const runtimeUrl = copilotkit.runtimeUrl;
6028
- const headers = copilotkit.headers ?? {};
6029
6025
  /**
6030
6026
  * Fire-and-forget emit; errors must not surface in render.
6031
6027
  * Failures are logged as warnings so they are diagnosable without
@@ -6042,7 +6038,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
6042
6038
  recordAnnotation({
6043
6039
  fetch: copilotkit.ɵruntimeFetch,
6044
6040
  runtimeUrl,
6045
- headers,
6041
+ headers: {},
6046
6042
  type: "set_learning_containers",
6047
6043
  payload: { containers },
6048
6044
  threadId
@@ -6066,11 +6062,10 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
6066
6062
  const capturedThreadId = threadId;
6067
6063
  return () => {
6068
6064
  const capturedRuntimeUrl = runtimeUrlRef.current;
6069
- const capturedHeaders = headersRef.current;
6070
6065
  if (capturedRuntimeUrl) recordAnnotation({
6071
6066
  fetch: runtimeFetchRef.current,
6072
6067
  runtimeUrl: capturedRuntimeUrl,
6073
- headers: capturedHeaders,
6068
+ headers: {},
6074
6069
  type: "set_learning_containers",
6075
6070
  payload: { containers: DEFAULT_CONTAINERS },
6076
6071
  threadId: capturedThreadId
@@ -8876,7 +8871,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
8876
8871
  message: "Runtime URL is not configured",
8877
8872
  retryable: false
8878
8873
  });
8879
- const headers = { ...core.headers };
8874
+ const headers = { ...await core.resolveHeaders() };
8880
8875
  let response;
8881
8876
  try {
8882
8877
  if (core.runtimeTransport === "single") {
@@ -9288,7 +9283,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
9288
9283
  threadStore.start();
9289
9284
  const context = copilotkit.runtimeUrl ? {
9290
9285
  runtimeUrl: copilotkit.runtimeUrl,
9291
- headers: { ...copilotkit.headers },
9292
9286
  wsUrl: copilotkit.intelligence?.wsUrl,
9293
9287
  agentId: resolvedAgentId
9294
9288
  } : null;
@@ -9384,7 +9378,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
9384
9378
  hasNativeIntelligenceRunActivity,
9385
9379
  copilotkit.runtimeConnectionStatus,
9386
9380
  copilotkit.runtimeUrl,
9387
- copilotkit.headers,
9381
+ copilotkit.ɵheadersGeneration,
9388
9382
  copilotkit.intelligence?.wsUrl,
9389
9383
  copilotkit.threadEndpoints?.realtimeMetadata,
9390
9384
  standaloneRunActivityStore,
@@ -12261,6 +12255,16 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
12261
12255
 
12262
12256
  //#endregion
12263
12257
  //#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
12258
+ /**
12259
+ * Drops `null`/`undefined` entries so a `CopilotKitHeadersSource` record (or
12260
+ * a builder's resolved record) matches `CopilotApiConfig.headers`'s
12261
+ * `Record<string, string>` shape. Mirrors core's own (internal-only)
12262
+ * `normalizeHeaders`.
12263
+ */
12264
+ function normalizeV1Headers(headers) {
12265
+ if (!headers) return {};
12266
+ return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
12267
+ }
12264
12268
  function CopilotKit({ children, ...props }) {
12265
12269
  const enabled = shouldShowDevConsole(props.showDevConsole);
12266
12270
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
@@ -12340,6 +12344,13 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
12340
12344
  * This will throw an error if the props are invalid.
12341
12345
  */
12342
12346
  validateProps(cpkProps);
12347
+ const headersPropRef = (0, react.useRef)(props.headers);
12348
+ headersPropRef.current = props.headers;
12349
+ const headersBuilderStateRef = (0, react.useRef)({
12350
+ fn: void 0,
12351
+ isAsync: false
12352
+ });
12353
+ const warnedAsyncHeadersRef = (0, react.useRef)(false);
12343
12354
  const publicApiKey = props.publicLicenseKey || props.publicApiKey;
12344
12355
  const chatApiEndpoint = props.runtimeUrl || _copilotkit_shared.COPILOT_CLOUD_CHAT_URL;
12345
12356
  const [actions, setActions] = (0, react.useState)({});
@@ -12407,19 +12418,46 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
12407
12418
  validTopics: props.guardrails_c?.validTopics || [],
12408
12419
  invalidTopics: props.guardrails_c?.invalidTopics || []
12409
12420
  } } } };
12410
- return {
12421
+ const config = {
12411
12422
  publicApiKey,
12412
12423
  ...cloud ? { cloud } : {},
12413
12424
  chatApiEndpoint,
12414
- headers: typeof props.headers === "function" ? props.headers() : props.headers || {},
12415
12425
  properties: props.properties || {},
12416
12426
  transcribeAudioUrl: props.transcribeAudioUrl,
12417
12427
  textToSpeechUrl: props.textToSpeechUrl,
12418
12428
  credentials: props.credentials
12419
12429
  };
12430
+ Object.defineProperty(config, "headers", {
12431
+ enumerable: true,
12432
+ configurable: true,
12433
+ get() {
12434
+ const source = headersPropRef.current;
12435
+ if (typeof source !== "function") return normalizeV1Headers(source);
12436
+ const state = headersBuilderStateRef.current;
12437
+ if (state.fn === source && state.isAsync) return {};
12438
+ const result = source();
12439
+ if (typeof result === "object" && result !== null && typeof result.then === "function") {
12440
+ headersBuilderStateRef.current = {
12441
+ fn: source,
12442
+ isAsync: true
12443
+ };
12444
+ result.then(void 0, () => {});
12445
+ if (process.env.NODE_ENV !== "production" && !warnedAsyncHeadersRef.current) {
12446
+ warnedAsyncHeadersRef.current = true;
12447
+ console.warn("[CopilotKit] An async `headers` builder is not supported by the v1 CopilotTask / GraphQL path; its headers are not sent there.");
12448
+ }
12449
+ return {};
12450
+ }
12451
+ headersBuilderStateRef.current = {
12452
+ fn: source,
12453
+ isAsync: false
12454
+ };
12455
+ return normalizeV1Headers(result);
12456
+ }
12457
+ });
12458
+ return config;
12420
12459
  }, [
12421
12460
  publicApiKey,
12422
- props.headers,
12423
12461
  props.properties,
12424
12462
  props.transcribeAudioUrl,
12425
12463
  props.textToSpeechUrl,
@@ -12427,27 +12465,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
12427
12465
  props.cloudRestrictToTopic,
12428
12466
  props.guardrails_c
12429
12467
  ]);
12430
- (0, react.useMemo)(() => {
12431
- const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
12432
- if (state.status === "authenticated" && state.authHeaders) return {
12433
- ...acc,
12434
- ...Object.entries(state.authHeaders).reduce((headers, [key, value]) => ({
12435
- ...headers,
12436
- [key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
12437
- }), {})
12438
- };
12439
- return acc;
12440
- }, {});
12441
- return {
12442
- ...copilotApiConfig.headers,
12443
- ...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
12444
- ...authHeaders
12445
- };
12446
- }, [
12447
- copilotApiConfig.headers,
12448
- copilotApiConfig.publicApiKey,
12449
- authStates
12450
- ]);
12451
12468
  const [internalErrorHandlers, _setInternalErrorHandler] = (0, react.useState)({});
12452
12469
  const setInternalErrorHandler = (0, react.useCallback)((handler) => {
12453
12470
  _setInternalErrorHandler((prev) => ({
@@ -12961,6 +12978,12 @@ Object.defineProperty(exports, 'CopilotKitCoreRuntimeConnectionStatus', {
12961
12978
  return _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus;
12962
12979
  }
12963
12980
  });
12981
+ Object.defineProperty(exports, 'CopilotKitHeaderResolutionError', {
12982
+ enumerable: true,
12983
+ get: function () {
12984
+ return _copilotkit_core.CopilotKitHeaderResolutionError;
12985
+ }
12986
+ });
12964
12987
  exports.CopilotKitInspector = CopilotKitInspector;
12965
12988
  exports.CopilotKitProvider = CopilotKitProvider;
12966
12989
  Object.defineProperty(exports, 'CopilotModalHeader', {
@@ -13163,6 +13186,12 @@ Object.defineProperty(exports, 'IntelligenceAgent', {
13163
13186
  });
13164
13187
  exports.IntelligenceIndicator = IntelligenceIndicator;
13165
13188
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
13189
+ Object.defineProperty(exports, 'IntelligenceReplayFailedError', {
13190
+ enumerable: true,
13191
+ get: function () {
13192
+ return _copilotkit_core.IntelligenceReplayFailedError;
13193
+ }
13194
+ });
13166
13195
  Object.defineProperty(exports, 'InterruptSchema', {
13167
13196
  enumerable: true,
13168
13197
  get: function () {
@@ -14300,5 +14329,11 @@ Object.defineProperty(exports, 'ɵthreadAdapterEvents', {
14300
14329
  return _copilotkit_core.ɵthreadAdapterEvents;
14301
14330
  }
14302
14331
  });
14332
+ Object.defineProperty(exports, 'ɵwithHeaderDefaults', {
14333
+ enumerable: true,
14334
+ get: function () {
14335
+ return _copilotkit_core.ɵwithHeaderDefaults;
14336
+ }
14337
+ });
14303
14338
  });
14304
14339
  //# sourceMappingURL=index.umd.js.map