@copilotkit/react-core 2.0.0-rc.14 → 2.0.0-rc.15

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.umd.js CHANGED
@@ -158,6 +158,48 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
158
158
  });
159
159
  });
160
160
 
161
+ //#endregion
162
+ //#region \0@oxc-project+runtime@0.112.0/helpers/typeof.js
163
+ function _typeof(o) {
164
+ "@babel/helpers - typeof";
165
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
166
+ return typeof o;
167
+ } : function(o) {
168
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
169
+ }, _typeof(o);
170
+ }
171
+
172
+ //#endregion
173
+ //#region \0@oxc-project+runtime@0.112.0/helpers/toPrimitive.js
174
+ function toPrimitive(t, r) {
175
+ if ("object" != _typeof(t) || !t) return t;
176
+ var e = t[Symbol.toPrimitive];
177
+ if (void 0 !== e) {
178
+ var i = e.call(t, r || "default");
179
+ if ("object" != _typeof(i)) return i;
180
+ throw new TypeError("@@toPrimitive must return a primitive value.");
181
+ }
182
+ return ("string" === r ? String : Number)(t);
183
+ }
184
+
185
+ //#endregion
186
+ //#region \0@oxc-project+runtime@0.112.0/helpers/toPropertyKey.js
187
+ function toPropertyKey(t) {
188
+ var i = toPrimitive(t, "string");
189
+ return "symbol" == _typeof(i) ? i : i + "";
190
+ }
191
+
192
+ //#endregion
193
+ //#region \0@oxc-project+runtime@0.112.0/helpers/defineProperty.js
194
+ function _defineProperty(e, r, t) {
195
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
196
+ value: t,
197
+ enumerable: !0,
198
+ configurable: !0,
199
+ writable: !0
200
+ }) : e[r] = t, e;
201
+ }
202
+
161
203
  //#endregion
162
204
  //#region src/lib/react-core.ts
163
205
  /**
@@ -182,12 +224,12 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
182
224
  ...config,
183
225
  ɵwaitForFrameworkUpdates: waitForReactCommit
184
226
  });
185
- this._renderToolCalls = [];
186
- this._hookRenderToolCalls = /* @__PURE__ */ new Map();
187
- this._cachedMergedRenderToolCalls = null;
188
- this._renderCustomMessages = [];
189
- this._renderActivityMessages = [];
190
- this._interruptElement = null;
227
+ _defineProperty(this, "_renderToolCalls", []);
228
+ _defineProperty(this, "_hookRenderToolCalls", /* @__PURE__ */ new Map());
229
+ _defineProperty(this, "_cachedMergedRenderToolCalls", null);
230
+ _defineProperty(this, "_renderCustomMessages", []);
231
+ _defineProperty(this, "_renderActivityMessages", []);
232
+ _defineProperty(this, "_interruptElement", null);
191
233
  this._renderToolCalls = config.renderToolCalls ?? [];
192
234
  this._renderCustomMessages = config.renderCustomMessages ?? [];
193
235
  this._renderActivityMessages = config.renderActivityMessages ?? [];
@@ -1882,7 +1924,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1882
1924
 
1883
1925
  //#endregion
1884
1926
  //#region package.json
1885
- var version$1 = "2.0.0-rc.14";
1927
+ var version$1 = "2.0.0-rc.15";
1886
1928
 
1887
1929
  //#endregion
1888
1930
  //#region src/components/CopilotKitInspector.tsx
@@ -3654,6 +3696,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3654
3696
  var GenerativeUIError = class extends Error {
3655
3697
  constructor(code, message) {
3656
3698
  super(message);
3699
+ _defineProperty(this, "code", void 0);
3657
3700
  this.name = "GenerativeUIError";
3658
3701
  this.code = code;
3659
3702
  }
@@ -3990,13 +4033,16 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3990
4033
  * gesture runs only from an event binding.
3991
4034
  */
3992
4035
  const invokeBasic = (name, args, origin) => {
3993
- const refused = callerError(name, _copilotkit_shared.GENERATIVE_UI_FUNCTIONS[name], origin);
4036
+ const info = _copilotkit_shared.GENERATIVE_UI_FUNCTIONS[name];
4037
+ const run = BASIC_FUNCTIONS[name];
4038
+ if (info === void 0 || run === void 0) throw new Error(`"${name}" is not a basic function`);
4039
+ const refused = callerError(name, info, origin);
3994
4040
  if (refused) return failWith(name, origin, refused);
3995
4041
  if (args !== void 0 && !(typeof args === "object" && args !== null && !Array.isArray(args))) return failWith(name, origin, new GenerativeUIError("invalid_arguments", `Invalid arguments for "${name}": args must be an object`));
3996
4042
  try {
3997
4043
  return {
3998
4044
  ok: true,
3999
- result: BASIC_FUNCTIONS[name](args ?? {})
4045
+ result: run(args ?? {})
4000
4046
  };
4001
4047
  } catch (error) {
4002
4048
  return failWith(name, origin, new GenerativeUIError(error instanceof ExpressionError ? "invalid_arguments" : "handler_failed", `"${name}" failed: ${messageOf(error)}`));
@@ -4149,8 +4195,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4149
4195
  */
4150
4196
  var BuildMemo = class {
4151
4197
  constructor() {
4152
- this.previous = /* @__PURE__ */ new Map();
4153
- this.current = /* @__PURE__ */ new Map();
4198
+ _defineProperty(this, "previous", /* @__PURE__ */ new Map());
4199
+ _defineProperty(this, "current", /* @__PURE__ */ new Map());
4154
4200
  }
4155
4201
  /**
4156
4202
  * The value of `key`. It is computed when no earlier value is there, or
@@ -4170,10 +4216,10 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4170
4216
  /** The results of the builds of one thread. See `BuildMarkdownSurfacesOptions.cache`. */
4171
4217
  var MarkdownBuildCache = class {
4172
4218
  constructor() {
4173
- this.segments = new BuildMemo();
4174
- this.fences = new BuildMemo();
4175
- this.drafts = new BuildMemo();
4176
- this.readdressed = /* @__PURE__ */ new WeakMap();
4219
+ _defineProperty(this, "segments", new BuildMemo());
4220
+ _defineProperty(this, "fences", new BuildMemo());
4221
+ _defineProperty(this, "drafts", new BuildMemo());
4222
+ _defineProperty(this, "readdressed", /* @__PURE__ */ new WeakMap());
4177
4223
  }
4178
4224
  endBuild() {
4179
4225
  this.segments.endBuild();
@@ -4688,10 +4734,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4688
4734
  constructor(manager, ui) {
4689
4735
  this.manager = manager;
4690
4736
  this.ui = ui;
4691
- this.fences = /* @__PURE__ */ new Map();
4692
- this.ingested = /* @__PURE__ */ new Map();
4693
- this.contents = /* @__PURE__ */ new Map();
4694
- this.caches = /* @__PURE__ */ new Map();
4737
+ _defineProperty(this, "functions", void 0);
4738
+ _defineProperty(this, "fences", /* @__PURE__ */ new Map());
4739
+ _defineProperty(this, "ingested", /* @__PURE__ */ new Map());
4740
+ _defineProperty(this, "contents", /* @__PURE__ */ new Map());
4741
+ _defineProperty(this, "caches", /* @__PURE__ */ new Map());
4695
4742
  this.functions = declaredFunctions(ui);
4696
4743
  }
4697
4744
  /**
@@ -4870,18 +4917,18 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4870
4917
  const MATH = {
4871
4918
  min: (args) => Math.min(...args),
4872
4919
  max: (args) => Math.max(...args),
4873
- abs: ([x]) => Math.abs(x),
4874
- floor: ([x]) => Math.floor(x),
4875
- ceil: ([x]) => Math.ceil(x),
4876
- round: ([x, decimals = 0]) => {
4920
+ abs: ([x = NaN]) => Math.abs(x),
4921
+ floor: ([x = NaN]) => Math.floor(x),
4922
+ ceil: ([x = NaN]) => Math.ceil(x),
4923
+ round: ([x = NaN, decimals = 0]) => {
4877
4924
  const factor = 10 ** Math.trunc(decimals);
4878
4925
  return Math.round(x * factor) / factor;
4879
4926
  },
4880
- pow: ([x, y]) => x ** y,
4881
- sqrt: ([x]) => Math.sqrt(x),
4882
- exp: ([x]) => Math.exp(x),
4883
- ln: ([x]) => Math.log(x),
4884
- log10: ([x]) => Math.log10(x)
4927
+ pow: ([x = NaN, y = NaN]) => x ** y,
4928
+ sqrt: ([x = NaN]) => Math.sqrt(x),
4929
+ exp: ([x = NaN]) => Math.exp(x),
4930
+ ln: ([x = NaN]) => Math.log(x),
4931
+ log10: ([x = NaN]) => Math.log10(x)
4885
4932
  };
4886
4933
  /** How many args a function takes, at least and at most; min and max take any. */
4887
4934
  const ARITY = {
@@ -4905,14 +4952,24 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4905
4952
  this.tokens = tokens;
4906
4953
  this.scope = scope;
4907
4954
  this.source = source;
4908
- this.pos = 0;
4909
- this.skipDepth = 0;
4955
+ _defineProperty(this, "pos", 0);
4956
+ _defineProperty(this, "skipDepth", 0);
4910
4957
  }
4911
4958
  parse() {
4912
4959
  const value = this.ternary();
4913
- if (this.tokens[this.pos].kind !== "end") this.fail(`unexpected "${this.text(this.tokens[this.pos])}"`);
4960
+ const token = this.peek();
4961
+ if (token.kind !== "end") this.fail(`unexpected "${this.text(token)}"`);
4914
4962
  return value;
4915
4963
  }
4964
+ /**
4965
+ * The token at `pos`. The parser never moves past the "end" token, which
4966
+ * `tokenize` always adds last, so there is always one.
4967
+ */
4968
+ peek() {
4969
+ const token = this.tokens[this.pos];
4970
+ if (token === void 0) throw new Error(`calc: no token at ${this.pos} in "${this.source}"`);
4971
+ return token;
4972
+ }
4916
4973
  fail(what) {
4917
4974
  throw new ExpressionError(`calc: ${what} in "${this.source}"`);
4918
4975
  }
@@ -4920,11 +4977,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4920
4977
  return token.kind === "end" ? "end" : String(token.value);
4921
4978
  }
4922
4979
  peekOp(...ops) {
4923
- const token = this.tokens[this.pos];
4980
+ const token = this.peek();
4924
4981
  return token.kind === "op" && ops.includes(token.value) ? token.value : void 0;
4925
4982
  }
4926
4983
  expectOp(op) {
4927
- if (this.peekOp(op) === void 0) this.fail(`expected "${op}" but found "${this.text(this.tokens[this.pos])}"`);
4984
+ if (this.peekOp(op) === void 0) this.fail(`expected "${op}" but found "${this.text(this.peek())}"`);
4928
4985
  this.pos++;
4929
4986
  }
4930
4987
  /**
@@ -5049,7 +5106,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5049
5106
  return value;
5050
5107
  }
5051
5108
  primary() {
5052
- const token = this.tokens[this.pos++];
5109
+ const token = this.peek();
5110
+ this.pos++;
5053
5111
  switch (token.kind) {
5054
5112
  case "number": return token.value;
5055
5113
  case "string": return token.value;
@@ -5332,7 +5390,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5332
5390
  constructor(source, state) {
5333
5391
  this.source = source;
5334
5392
  this.state = state;
5335
- this.pos = 0;
5393
+ _defineProperty(this, "pos", 0);
5336
5394
  }
5337
5395
  parse() {
5338
5396
  const value = this.expression();
@@ -5524,23 +5582,33 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5524
5582
  constructor(ui, options = {}) {
5525
5583
  this.ui = ui;
5526
5584
  this.options = options;
5527
- this.surfaces = /* @__PURE__ */ new Map();
5528
- this.bookkeeping = /* @__PURE__ */ new Map();
5529
- this.listeners = /* @__PURE__ */ new Set();
5530
- this.targets = /* @__PURE__ */ new Map();
5531
- this.state = {};
5532
- this.owned = /* @__PURE__ */ new Map();
5533
- this.deletedKeys = /* @__PURE__ */ new Set();
5534
- this.linked = /* @__PURE__ */ new Map();
5535
- this.version = 0;
5536
- this.subscribe = (listener) => {
5585
+ _defineProperty(this, "surfaces", /* @__PURE__ */ new Map());
5586
+ _defineProperty(this, "bookkeeping", /* @__PURE__ */ new Map());
5587
+ _defineProperty(this, "listeners", /* @__PURE__ */ new Set());
5588
+ _defineProperty(this, "targets", /* @__PURE__ */ new Map());
5589
+ _defineProperty(this, "state", {});
5590
+ _defineProperty(this, "owned", /* @__PURE__ */ new Map());
5591
+ _defineProperty(this, "deletedKeys", /* @__PURE__ */ new Set());
5592
+ _defineProperty(this, "linked", /* @__PURE__ */ new Map());
5593
+ _defineProperty(this, "webCoreCatalog", void 0);
5594
+ _defineProperty(this, "activeThreadId", void 0);
5595
+ _defineProperty(this, "version", 0);
5596
+ _defineProperty(this, "subscribe", (listener) => {
5537
5597
  this.listeners.add(listener);
5538
5598
  return () => {
5539
5599
  this.listeners.delete(listener);
5540
5600
  };
5541
- };
5542
- this.getVersion = () => this.version;
5543
- this.getState = () => this.state;
5601
+ });
5602
+ _defineProperty(this, "getVersion", () => this.version);
5603
+ _defineProperty(
5604
+ this,
5605
+ /**
5606
+ * The app state object. It is the same object until a key changes, so it
5607
+ * can be a `useSyncExternalStore` snapshot.
5608
+ */
5609
+ "getState",
5610
+ () => this.state
5611
+ );
5544
5612
  this.webCoreCatalog = new _a2ui_web_core_v0_9.Catalog(ui.id, [...ui.components.keys()].map((name) => ({
5545
5613
  name,
5546
5614
  schema: zod.any()
@@ -6605,11 +6673,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
6605
6673
  var NodeBoundary = class extends react.Component {
6606
6674
  constructor(..._args) {
6607
6675
  super(..._args);
6608
- this.state = {
6676
+ _defineProperty(this, "state", {
6609
6677
  error: null,
6610
6678
  revision: this.props.revision
6611
- };
6612
- this.retry = () => this.setState({ error: null });
6679
+ });
6680
+ _defineProperty(this, "retry", () => this.setState({ error: null }));
6613
6681
  }
6614
6682
  static getDerivedStateFromError(error) {
6615
6683
  return { error };
@@ -6650,7 +6718,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
6650
6718
  var SurfaceBoundary = class extends react.Component {
6651
6719
  constructor(..._args2) {
6652
6720
  super(..._args2);
6653
- this.state = { error: null };
6721
+ _defineProperty(this, "state", { error: null });
6654
6722
  }
6655
6723
  static getDerivedStateFromError(error) {
6656
6724
  return { error };
@@ -10022,7 +10090,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10022
10090
  try {
10023
10091
  maybePromise = handler({
10024
10092
  event: legacyEvent,
10025
- interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
10093
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
10026
10094
  interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
10027
10095
  resolve: resolveRef.current,
10028
10096
  cancel: cancelRef.current
@@ -10051,7 +10119,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10051
10119
  if (!isEnabled(legacyEvent)) return null;
10052
10120
  return renderRef.current({
10053
10121
  event: legacyEvent,
10054
- interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
10122
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
10055
10123
  interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
10056
10124
  result: handlerResult,
10057
10125
  resolve,
@@ -14231,10 +14299,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14231
14299
  const [fallbackThreadId, setFallbackThreadId] = (0, react.useState)(messages[0]?.id);
14232
14300
  const previousMessageIds = (0, react.useRef)(/* @__PURE__ */ new Set());
14233
14301
  (0, react.useEffect)(() => {
14234
- if (messages.length === 0) return;
14302
+ const firstMessage = messages[0];
14303
+ if (firstMessage === void 0) return;
14235
14304
  const overlaps = messages.some((message) => previousMessageIds.current.has(message.id));
14236
14305
  previousMessageIds.current = new Set(messages.map((message) => message.id));
14237
- if (!overlaps) setFallbackThreadId(messages[0].id);
14306
+ if (!overlaps) setFallbackThreadId(firstMessage.id);
14238
14307
  }, [messages]);
14239
14308
  const scrollThreadId = configuredThreadId ?? fallbackThreadId;
14240
14309
  const [inputContainerEl, setInputContainerEl] = (0, react.useState)(null);
@@ -15407,7 +15476,10 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
15407
15476
  const effectiveMode = isTranscribing ? "processing" : transcribeMode;
15408
15477
  const messages = (0, react.useMemo)(() => [...agent.messages], [(0, _copilotkit_core.ɵmessagesFingerprint)(agent.messages)]);
15409
15478
  const lastUserMessageId = (0, react.useMemo)(() => {
15410
- for (let i = messages.length - 1; i >= 0; i--) if (messages[i].role === "user") return messages[i].id;
15479
+ for (let i = messages.length - 1; i >= 0; i--) {
15480
+ const message = messages[i];
15481
+ if (message?.role === "user") return message.id;
15482
+ }
15411
15483
  return null;
15412
15484
  }, [messages]);
15413
15485
  const [sendNonce, setSendNonce] = (0, react.useState)(0);