@copilotkit/react-core 1.79.1 → 1.79.2-canary.1792172552

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.
@@ -180,7 +180,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
180
180
  * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
181
181
  * class instances, and other exotic objects that happen to have typeof "object".
182
182
  */
183
- function isPlainObject(obj) {
183
+ function isPlainObject$1(obj) {
184
184
  return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
185
185
  }
186
186
  /**
@@ -199,7 +199,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
199
199
  function useShallowStableRef(value) {
200
200
  const ref = (0, react.useRef)(value);
201
201
  if (ref.current === value) return ref.current;
202
- if (isPlainObject(ref.current) && isPlainObject(value)) {
202
+ if (isPlainObject$1(ref.current) && isPlainObject$1(value)) {
203
203
  if (shallowEqual(ref.current, value)) return ref.current;
204
204
  }
205
205
  ref.current = value;
@@ -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.79.1";
1769
+ var version = "1.79.2-canary.1792172552";
1770
1770
 
1771
1771
  //#endregion
1772
1772
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -4035,12 +4035,86 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4035
4035
  }), [renderActivityMessage, findRenderer]);
4036
4036
  }
4037
4037
 
4038
+ //#endregion
4039
+ //#region src/v2/hooks/tool-registration.ts
4040
+ /**
4041
+ * Deps comparison shared by `useFrontendTool` (and through it
4042
+ * `useHumanInTheLoop` and `useComponent`) and `useRenderTool`. Not part of the
4043
+ * public API.
4044
+ */
4045
+ const EMPTY_DEPS$1 = [];
4046
+ function isPlainObject(value) {
4047
+ const proto = Object.getPrototypeOf(value);
4048
+ return proto === Object.prototype || proto === null;
4049
+ }
4050
+ /**
4051
+ * Plain data (primitives, plain objects, arrays, dates) compares by value.
4052
+ * Functions always compare equal: these hooks used to compare
4053
+ * `JSON.stringify(deps)`, which turns every function into `null`, and a
4054
+ * function that counted as changed would re-register on every render when it
4055
+ * is written inline (and loop in a component that also reads
4056
+ * `useRenderToolCall`). Everything else (class instances, maps, sets) compares
4057
+ * by identity. A cycle inside plain data is safe: a pair already being
4058
+ * compared counts as equal for that branch.
4059
+ */
4060
+ function depEqual(a, b, seen) {
4061
+ if (Object.is(a, b)) return true;
4062
+ if (typeof a === "function" && typeof b === "function") return true;
4063
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
4064
+ if (a instanceof Date && b instanceof Date) return Object.is(a.getTime(), b.getTime());
4065
+ const aIsArray = Array.isArray(a);
4066
+ if (aIsArray !== Array.isArray(b)) return false;
4067
+ if (!aIsArray && !(isPlainObject(a) && isPlainObject(b))) return false;
4068
+ if (seen.get(a) === b) return true;
4069
+ seen.set(a, b);
4070
+ if (aIsArray) {
4071
+ const left = a;
4072
+ const right = b;
4073
+ if (left.length !== right.length) return false;
4074
+ for (let i = 0; i < left.length; i++) if (!depEqual(left[i], right[i], seen)) return false;
4075
+ return true;
4076
+ }
4077
+ const left = a;
4078
+ const right = b;
4079
+ const leftKeys = Object.keys(left);
4080
+ if (leftKeys.length !== Object.keys(right).length) return false;
4081
+ for (const key of leftKeys) {
4082
+ if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
4083
+ if (!depEqual(left[key], right[key], seen)) return false;
4084
+ }
4085
+ return true;
4086
+ }
4087
+ /** Whether two deps arrays are equal. A change in length is always a change. */
4088
+ function depsEqual(prev, next) {
4089
+ if (prev.length !== next.length) return false;
4090
+ const seen = /* @__PURE__ */ new Map();
4091
+ for (let i = 0; i < prev.length; i++) if (!depEqual(prev[i], next[i], seen)) return false;
4092
+ return true;
4093
+ }
4094
+ /**
4095
+ * Turns a caller's `deps` array into a number that changes exactly when the
4096
+ * deps change, by the rules of {@link depsEqual}. Put the number, not the
4097
+ * array, in the registration effect's dependency list: that keeps the list a
4098
+ * constant length and never serializes a value.
4099
+ */
4100
+ function useDepsVersion(deps) {
4101
+ const next = deps ?? EMPTY_DEPS$1;
4102
+ const ref = (0, react.useRef)({
4103
+ deps: next,
4104
+ version: 0
4105
+ });
4106
+ if (ref.current.deps !== next && !depsEqual(ref.current.deps, next)) ref.current = {
4107
+ deps: next,
4108
+ version: ref.current.version + 1
4109
+ };
4110
+ return ref.current.version;
4111
+ }
4112
+
4038
4113
  //#endregion
4039
4114
  //#region src/v2/hooks/use-frontend-tool.tsx
4040
- const EMPTY_DEPS$2 = [];
4041
4115
  function useFrontendTool(tool, deps) {
4042
4116
  const { copilotkit } = useCopilotKit();
4043
- const extraDeps = deps ?? EMPTY_DEPS$2;
4117
+ const depsVersion = useDepsVersion(deps);
4044
4118
  (0, react.useLayoutEffect)(() => {
4045
4119
  const name = tool.name;
4046
4120
  if (copilotkit.getTool({
@@ -4064,14 +4138,14 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4064
4138
  tool.name,
4065
4139
  tool.available,
4066
4140
  copilotkit,
4067
- JSON.stringify(extraDeps),
4141
+ depsVersion,
4068
4142
  JSON.stringify(tool.webmcp ?? null)
4069
4143
  ]);
4070
4144
  }
4071
4145
 
4072
4146
  //#endregion
4073
4147
  //#region src/v2/hooks/use-frontend-tools.tsx
4074
- const EMPTY_DEPS$1 = [];
4148
+ const EMPTY_DEPS = [];
4075
4149
  const EMPTY_TOOLS = [];
4076
4150
  /**
4077
4151
  * Register a list of frontend tools whose length can change between renders.
@@ -4125,7 +4199,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4125
4199
  function useFrontendTools(tools, deps) {
4126
4200
  const { copilotkit } = useCopilotKit();
4127
4201
  const toolList = tools ?? EMPTY_TOOLS;
4128
- const extraDeps = deps ?? EMPTY_DEPS$1;
4202
+ const extraDeps = deps ?? EMPTY_DEPS;
4129
4203
  (0, react.useLayoutEffect)(() => {
4130
4204
  const deduped = /* @__PURE__ */ new Map();
4131
4205
  for (const tool of toolList) {
@@ -4236,8 +4310,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4236
4310
 
4237
4311
  //#endregion
4238
4312
  //#region src/v2/hooks/use-render-tool.tsx
4239
- const EMPTY_DEPS = [];
4240
- /**
4313
+ /**
4241
4314
  * Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
4242
4315
  *
4243
4316
  * Key behavior:
@@ -4280,7 +4353,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4280
4353
  */
4281
4354
  function useRenderTool(config, deps) {
4282
4355
  const { copilotkit } = useCopilotKit();
4283
- const extraDeps = deps ?? EMPTY_DEPS;
4356
+ const depsVersion = useDepsVersion(deps);
4284
4357
  (0, react.useEffect)(() => {
4285
4358
  const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
4286
4359
  name: "*",
@@ -4312,7 +4385,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
4312
4385
  }, [
4313
4386
  config.name,
4314
4387
  copilotkit,
4315
- JSON.stringify(extraDeps)
4388
+ depsVersion
4316
4389
  ]);
4317
4390
  }
4318
4391
 
@@ -7810,6 +7883,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7810
7883
  (0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
7811
7884
  }, [rowKeyStore, renderedMessages]);
7812
7885
  const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
7886
+ const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
7887
+ const rowKeys = (0, react.useMemo)(() => rows.map(rowKey), [rows, rowRenderKeys]);
7813
7888
  const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
7814
7889
  const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
7815
7890
  const groupStateThreadRef = (0, react.useRef)(config?.threadId);
@@ -7883,6 +7958,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7883
7958
  total: 0,
7884
7959
  sizes: /* @__PURE__ */ new Map()
7885
7960
  });
7961
+ const rowKeysRef = react.default.useRef(rowKeys);
7962
+ rowKeysRef.current = rowKeys;
7886
7963
  const firstMessageId = deduplicatedMessages[0]?.id;
7887
7964
  const measuredThreadRef = react.default.useRef(firstMessageId);
7888
7965
  if (measuredThreadRef.current !== firstMessageId) {
@@ -7892,6 +7969,16 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7892
7969
  sizes: /* @__PURE__ */ new Map()
7893
7970
  };
7894
7971
  }
7972
+ const measuredKeysRef = react.default.useRef(rowKeys);
7973
+ if (measuredKeysRef.current !== rowKeys) {
7974
+ measuredKeysRef.current = rowKeys;
7975
+ const live = new Set(rowKeys);
7976
+ const measured = measuredRef.current;
7977
+ for (const [key, height] of measured.sizes) if (!live.has(key)) {
7978
+ measured.sizes.delete(key);
7979
+ measured.total -= height;
7980
+ }
7981
+ }
7895
7982
  const estimateRowSize = react.default.useCallback(() => {
7896
7983
  const { total, sizes } = measuredRef.current;
7897
7984
  return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
@@ -7899,13 +7986,15 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7899
7986
  const measureRowElement = react.default.useCallback((el) => {
7900
7987
  const height = el?.getBoundingClientRect().height ?? 0;
7901
7988
  const index = Number(el?.dataset?.index);
7902
- if (height > 0 && Number.isInteger(index)) {
7989
+ const key = Number.isInteger(index) ? rowKeysRef.current[index] : void 0;
7990
+ if (height > 0 && key !== void 0) {
7903
7991
  const { total, sizes } = measuredRef.current;
7904
- measuredRef.current.total = total - (sizes.get(index) ?? 0) + height;
7905
- sizes.set(index, height);
7992
+ measuredRef.current.total = total - (sizes.get(key) ?? 0) + height;
7993
+ sizes.set(key, height);
7906
7994
  }
7907
7995
  return height;
7908
7996
  }, []);
7997
+ const getRowKey = react.default.useCallback((index) => rowKeys[index] ?? index, [rowKeys]);
7909
7998
  const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
7910
7999
  const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
7911
8000
  if (isPinnedToBottomRef.current) return false;
@@ -7916,6 +8005,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7916
8005
  count: shouldVirtualize ? rows.length : 0,
7917
8006
  getScrollElement: () => scrollElement,
7918
8007
  estimateSize: estimateRowSize,
8008
+ getItemKey: getRowKey,
7919
8009
  overscan: 5,
7920
8010
  measureElement: measureRowElement,
7921
8011
  initialRect: {
@@ -7979,7 +8069,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
7979
8069
  }, `intelligence-${intelligenceTurnId}`));
7980
8070
  return elements.filter(Boolean);
7981
8071
  };
7982
- const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
7983
8072
  const renderRow = (row) => {
7984
8073
  if (row.type === "message") return renderMessageBlock(row.message);
7985
8074
  const Wrapper = row.wrapper;
@@ -13186,6 +13275,12 @@ Object.defineProperty(exports, 'IntelligenceAgent', {
13186
13275
  });
13187
13276
  exports.IntelligenceIndicator = IntelligenceIndicator;
13188
13277
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
13278
+ Object.defineProperty(exports, 'IntelligenceReplayFailedError', {
13279
+ enumerable: true,
13280
+ get: function () {
13281
+ return _copilotkit_core.IntelligenceReplayFailedError;
13282
+ }
13283
+ });
13189
13284
  Object.defineProperty(exports, 'InterruptSchema', {
13190
13285
  enumerable: true,
13191
13286
  get: function () {