@copilotkit/react-core 2.0.0-rc.13 → 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.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_MarkdownSurfaces = require('./MarkdownSurfaces-EGmsCZWN.cjs');
4
+ const require_MarkdownSurfaces = require('./MarkdownSurfaces-ChOKawIN.cjs');
5
5
  let _copilotkit_core = require("@copilotkit/core");
6
6
  let _ag_ui_client = require("@ag-ui/client");
7
7
  let react = require("react");
@@ -1242,7 +1242,7 @@ function useRenderToolCall() {
1242
1242
 
1243
1243
  //#endregion
1244
1244
  //#region package.json
1245
- var version$1 = "2.0.0-rc.13";
1245
+ var version$1 = "2.0.0-rc.15";
1246
1246
 
1247
1247
  //#endregion
1248
1248
  //#region src/components/CopilotKitInspector.tsx
@@ -3090,13 +3090,16 @@ function createGenerativeUIDispatcher(options) {
3090
3090
  * gesture runs only from an event binding.
3091
3091
  */
3092
3092
  const invokeBasic = (name, args, origin) => {
3093
- const refused = callerError(name, _copilotkit_shared.GENERATIVE_UI_FUNCTIONS[name], origin);
3093
+ const info = _copilotkit_shared.GENERATIVE_UI_FUNCTIONS[name];
3094
+ const run = require_MarkdownSurfaces.BASIC_FUNCTIONS[name];
3095
+ if (info === void 0 || run === void 0) throw new Error(`"${name}" is not a basic function`);
3096
+ const refused = callerError(name, info, origin);
3094
3097
  if (refused) return failWith(name, origin, refused);
3095
3098
  if (args !== void 0 && !(typeof args === "object" && args !== null && !Array.isArray(args))) return failWith(name, origin, new require_MarkdownSurfaces.GenerativeUIError("invalid_arguments", `Invalid arguments for "${name}": args must be an object`));
3096
3099
  try {
3097
3100
  return {
3098
3101
  ok: true,
3099
- result: require_MarkdownSurfaces.BASIC_FUNCTIONS[name](args ?? {})
3102
+ result: run(args ?? {})
3100
3103
  };
3101
3104
  } catch (error) {
3102
3105
  return failWith(name, origin, new require_MarkdownSurfaces.GenerativeUIError(error instanceof require_MarkdownSurfaces.ExpressionError ? "invalid_arguments" : "handler_failed", `"${name}" failed: ${messageOf(error)}`));
@@ -3270,31 +3273,47 @@ function summarizeRejections(rejections) {
3270
3273
  * with `getState()`.
3271
3274
  */
3272
3275
  var GenerativeUISurfaceManager = class {
3276
+ surfaces = /* @__PURE__ */ new Map();
3277
+ bookkeeping = /* @__PURE__ */ new Map();
3278
+ listeners = /* @__PURE__ */ new Set();
3279
+ /** Mounts of each target id, in mount order. */
3280
+ targets = /* @__PURE__ */ new Map();
3281
+ state = {};
3282
+ /**
3283
+ * User-owned data model values, by surface key, then by path. Kept when a
3284
+ * surface is rebuilt. Cleared when the surface is deleted.
3285
+ */
3286
+ owned = /* @__PURE__ */ new Map();
3287
+ /**
3288
+ * Keys of the surfaces that a `deleteSurface` removed. A surface id is
3289
+ * unique for the life of the page, so a key stays here when its surface is
3290
+ * built again.
3291
+ */
3292
+ deletedKeys = /* @__PURE__ */ new Set();
3293
+ /**
3294
+ * Surfaces that share their data model, by surface key: the parts of a
3295
+ * chat surface that the prose lift split. A user write to one part goes
3296
+ * to every part, so an input in one part drives a binding in another.
3297
+ */
3298
+ linked = /* @__PURE__ */ new Map();
3299
+ webCoreCatalog;
3300
+ activeThreadId;
3301
+ version = 0;
3273
3302
  constructor(ui, options = {}) {
3274
3303
  this.ui = ui;
3275
3304
  this.options = options;
3276
- this.surfaces = /* @__PURE__ */ new Map();
3277
- this.bookkeeping = /* @__PURE__ */ new Map();
3278
- this.listeners = /* @__PURE__ */ new Set();
3279
- this.targets = /* @__PURE__ */ new Map();
3280
- this.state = {};
3281
- this.owned = /* @__PURE__ */ new Map();
3282
- this.deletedKeys = /* @__PURE__ */ new Set();
3283
- this.linked = /* @__PURE__ */ new Map();
3284
- this.version = 0;
3285
- this.subscribe = (listener) => {
3286
- this.listeners.add(listener);
3287
- return () => {
3288
- this.listeners.delete(listener);
3289
- };
3290
- };
3291
- this.getVersion = () => this.version;
3292
- this.getState = () => this.state;
3293
3305
  this.webCoreCatalog = new _a2ui_web_core_v0_9.Catalog(ui.id, [...ui.components.keys()].map((name) => ({
3294
3306
  name,
3295
3307
  schema: zod.any()
3296
3308
  })), []);
3297
3309
  }
3310
+ subscribe = (listener) => {
3311
+ this.listeners.add(listener);
3312
+ return () => {
3313
+ this.listeners.delete(listener);
3314
+ };
3315
+ };
3316
+ getVersion = () => this.version;
3298
3317
  notify() {
3299
3318
  this.version++;
3300
3319
  for (const listener of [...this.listeners]) listener();
@@ -3480,6 +3499,11 @@ var GenerativeUISurfaceManager = class {
3480
3499
  names: new Set(components)
3481
3500
  };
3482
3501
  }
3502
+ /**
3503
+ * The app state object. It is the same object until a key changes, so it
3504
+ * can be a `useSyncExternalStore` snapshot.
3505
+ */
3506
+ getState = () => this.state;
3483
3507
  /** Sets one state key. Notifies only when the value changed. */
3484
3508
  setState(key, value) {
3485
3509
  if (Object.hasOwn(this.state, key) && Object.is(this.state[key], value)) return;
@@ -4300,17 +4324,17 @@ function waitForReactCommit() {
4300
4324
  return new Promise((resolve) => setTimeout(resolve, 0));
4301
4325
  }
4302
4326
  var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
4327
+ _renderToolCalls = [];
4328
+ _hookRenderToolCalls = /* @__PURE__ */ new Map();
4329
+ _cachedMergedRenderToolCalls = null;
4330
+ _renderCustomMessages = [];
4331
+ _renderActivityMessages = [];
4332
+ _interruptElement = null;
4303
4333
  constructor(config) {
4304
4334
  super({
4305
4335
  ...config,
4306
4336
  ɵwaitForFrameworkUpdates: waitForReactCommit
4307
4337
  });
4308
- this._renderToolCalls = [];
4309
- this._hookRenderToolCalls = /* @__PURE__ */ new Map();
4310
- this._cachedMergedRenderToolCalls = null;
4311
- this._renderCustomMessages = [];
4312
- this._renderActivityMessages = [];
4313
- this._interruptElement = null;
4314
4338
  this._renderToolCalls = config.renderToolCalls ?? [];
4315
4339
  this._renderCustomMessages = config.renderCustomMessages ?? [];
4316
4340
  this._renderActivityMessages = config.renderActivityMessages ?? [];
@@ -6795,7 +6819,7 @@ function useInterrupt(config) {
6795
6819
  try {
6796
6820
  maybePromise = handler({
6797
6821
  event: legacyEvent,
6798
- interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
6822
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
6799
6823
  interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
6800
6824
  resolve: resolveRef.current,
6801
6825
  cancel: cancelRef.current
@@ -6824,7 +6848,7 @@ function useInterrupt(config) {
6824
6848
  if (!isEnabled(legacyEvent)) return null;
6825
6849
  return renderRef.current({
6826
6850
  event: legacyEvent,
6827
- interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
6851
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
6828
6852
  interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
6829
6853
  result: handlerResult,
6830
6854
  resolve,
@@ -10857,10 +10881,11 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
10857
10881
  const [fallbackThreadId, setFallbackThreadId] = (0, react.useState)(messages[0]?.id);
10858
10882
  const previousMessageIds = (0, react.useRef)(/* @__PURE__ */ new Set());
10859
10883
  (0, react.useEffect)(() => {
10860
- if (messages.length === 0) return;
10884
+ const firstMessage = messages[0];
10885
+ if (firstMessage === void 0) return;
10861
10886
  const overlaps = messages.some((message) => previousMessageIds.current.has(message.id));
10862
10887
  previousMessageIds.current = new Set(messages.map((message) => message.id));
10863
- if (!overlaps) setFallbackThreadId(messages[0].id);
10888
+ if (!overlaps) setFallbackThreadId(firstMessage.id);
10864
10889
  }, [messages]);
10865
10890
  const scrollThreadId = configuredThreadId ?? fallbackThreadId;
10866
10891
  const [inputContainerEl, setInputContainerEl] = (0, react.useState)(null);
@@ -12033,7 +12058,10 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
12033
12058
  const effectiveMode = isTranscribing ? "processing" : transcribeMode;
12034
12059
  const messages = (0, react.useMemo)(() => [...agent.messages], [(0, _copilotkit_core.ɵmessagesFingerprint)(agent.messages)]);
12035
12060
  const lastUserMessageId = (0, react.useMemo)(() => {
12036
- for (let i = messages.length - 1; i >= 0; i--) if (messages[i].role === "user") return messages[i].id;
12061
+ for (let i = messages.length - 1; i >= 0; i--) {
12062
+ const message = messages[i];
12063
+ if (message?.role === "user") return message.id;
12064
+ }
12037
12065
  return null;
12038
12066
  }, [messages]);
12039
12067
  const [sendNonce, setSendNonce] = (0, react.useState)(0);