@copilotkit/react-core 1.55.2-next.0 → 1.55.2-next.1

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
@@ -149,14 +149,11 @@ react_markdown = __toESM(react_markdown);
149
149
  var _ref, _parentConfig$isModal, _parentConfig$setModa;
150
150
  const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
151
151
  const stableLabels = useShallowStableRef(labels);
152
- const mergedLabels = (0, react.useMemo)(() => {
153
- var _parentConfig$labels;
154
- return {
155
- ...CopilotChatDefaultLabels,
156
- ...(_parentConfig$labels = parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels) !== null && _parentConfig$labels !== void 0 ? _parentConfig$labels : {},
157
- ...stableLabels !== null && stableLabels !== void 0 ? stableLabels : {}
158
- };
159
- }, [stableLabels, parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels]);
152
+ const mergedLabels = (0, react.useMemo)(() => ({
153
+ ...CopilotChatDefaultLabels,
154
+ ...parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels,
155
+ ...stableLabels
156
+ }), [stableLabels, parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels]);
160
157
  const resolvedAgentId = (_ref = agentId !== null && agentId !== void 0 ? agentId : parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.agentId) !== null && _ref !== void 0 ? _ref : _copilotkit_shared.DEFAULT_AGENT_ID;
161
158
  const resolvedThreadId = (0, react.useMemo)(() => {
162
159
  if (threadId) return threadId;
@@ -1314,9 +1311,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
1314
1311
  if (!agent) return;
1315
1312
  message.userAction;
1316
1313
  try {
1317
- var _copilotkit$propertie;
1318
1314
  copilotkit.setProperties({
1319
- ...(_copilotkit$propertie = copilotkit.properties) !== null && _copilotkit$propertie !== void 0 ? _copilotkit$propertie : {},
1315
+ ...copilotkit.properties,
1320
1316
  a2uiAction: message
1321
1317
  });
1322
1318
  await copilotkit.runAgent({ agent });
@@ -4410,8 +4406,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4410
4406
  * 5) last cached snapshot for stateRenderId
4411
4407
  */
4412
4408
  function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
4413
- var _reverse$find, _agentMessages$messag, _existingClaim$stateS, _existingClaim$stateS2;
4414
- const lastAssistantId = agentMessages ? (_reverse$find = [...agentMessages].reverse().find((msg) => msg.role === "assistant")) === null || _reverse$find === void 0 ? void 0 : _reverse$find.id : void 0;
4409
+ var _toReversed$find, _agentMessages$messag, _existingClaim$stateS, _existingClaim$stateS2;
4410
+ const lastAssistantId = agentMessages ? (_toReversed$find = [...agentMessages].toReversed().find((msg) => msg.role === "assistant")) === null || _toReversed$find === void 0 ? void 0 : _toReversed$find.id : void 0;
4415
4411
  const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
4416
4412
  const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
4417
4413
  const messageRole = messageIndex >= 0 && agentMessages ? (_agentMessages$messag = agentMessages[messageIndex]) === null || _agentMessages$messag === void 0 ? void 0 : _agentMessages$messag.role : void 0;
@@ -4475,13 +4471,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4475
4471
  return () => {
4476
4472
  const existingClaim = claimsRef.current[message.id];
4477
4473
  if ((existingClaim === null || existingClaim === void 0 ? void 0 : existingClaim.stateSnapshot) && Object.keys(existingClaim.stateSnapshot).length > 0) {
4478
- var _store$LAST_SNAPSHOTS4, _existingClaim$runId, _store$LAST_SNAPSHOTS5, _existingClaim$runId2;
4479
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS4 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS4 !== void 0 ? _store$LAST_SNAPSHOTS4 : {} };
4474
+ var _existingClaim$runId, _existingClaim$runId2;
4475
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
4480
4476
  const cacheKey = `${existingClaim.stateRenderId}::${(_existingClaim$runId = existingClaim.runId) !== null && _existingClaim$runId !== void 0 ? _existingClaim$runId : "pending"}`;
4481
4477
  snapshotCache[cacheKey] = existingClaim.stateSnapshot;
4482
4478
  snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
4483
4479
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
4484
- const messageCache = { ...(_store$LAST_SNAPSHOTS5 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS5 !== void 0 ? _store$LAST_SNAPSHOTS5 : {} };
4480
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
4485
4481
  messageCache[message.id] = {
4486
4482
  snapshot: existingClaim.stateSnapshot,
4487
4483
  runId: (_existingClaim$runId2 = existingClaim.runId) !== null && _existingClaim$runId2 !== void 0 ? _existingClaim$runId2 : effectiveRunId
@@ -4536,14 +4532,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4536
4532
  const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
4537
4533
  if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
4538
4534
  if (!claimsRef.current[message.id].locked || snapshotChanged) {
4539
- var _store$LAST_SNAPSHOTS6, _store$LAST_SNAPSHOTS7;
4540
4535
  claimsRef.current[message.id].stateSnapshot = snapshot;
4541
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS6 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS6 !== void 0 ? _store$LAST_SNAPSHOTS6 : {} };
4536
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
4542
4537
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
4543
4538
  snapshotCache[cacheKey] = snapshot;
4544
4539
  snapshotCache[`${stateRenderId}::latest`] = snapshot;
4545
4540
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
4546
- const messageCache = { ...(_store$LAST_SNAPSHOTS7 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS7 !== void 0 ? _store$LAST_SNAPSHOTS7 : {} };
4541
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
4547
4542
  messageCache[message.id] = {
4548
4543
  snapshot,
4549
4544
  runId: effectiveRunId
@@ -4553,14 +4548,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4553
4548
  }
4554
4549
  } else if (snapshotForClaim) {
4555
4550
  if (!claimsRef.current[message.id].stateSnapshot) {
4556
- var _store$LAST_SNAPSHOTS8, _store$LAST_SNAPSHOTS9;
4557
4551
  claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
4558
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS8 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS8 !== void 0 ? _store$LAST_SNAPSHOTS8 : {} };
4552
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
4559
4553
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
4560
4554
  snapshotCache[cacheKey] = snapshotForClaim;
4561
4555
  snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
4562
4556
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
4563
- const messageCache = { ...(_store$LAST_SNAPSHOTS9 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS9 !== void 0 ? _store$LAST_SNAPSHOTS9 : {} };
4557
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
4564
4558
  messageCache[message.id] = {
4565
4559
  snapshot: snapshotForClaim,
4566
4560
  runId: effectiveRunId
@@ -4912,7 +4906,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4912
4906
  return acc;
4913
4907
  }, {});
4914
4908
  return {
4915
- ...copilotApiConfig.headers || {},
4909
+ ...copilotApiConfig.headers,
4916
4910
  ...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
4917
4911
  ...authHeaders
4918
4912
  };
@@ -4992,12 +4986,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4992
4986
  const [interruptActions, _setInterruptActions] = (0, react.useState)({});
4993
4987
  const setInterruptAction = (0, react.useCallback)((action) => {
4994
4988
  _setInterruptActions((prev) => {
4995
- var _prev$action$id;
4996
4989
  if (action == null || !action.id) return prev;
4997
4990
  return {
4998
4991
  ...prev,
4999
4992
  [action.id]: {
5000
- ...(_prev$action$id = prev[action.id]) !== null && _prev$action$id !== void 0 ? _prev$action$id : {},
4993
+ ...prev[action.id],
5001
4994
  ...action
5002
4995
  }
5003
4996
  };
@@ -5340,7 +5333,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5340
5333
  }
5341
5334
  let historyCutoff = [messages[0]];
5342
5335
  if (messages.length > 2 && reloadMessageIndex !== 0) {
5343
- const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
5336
+ const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).toReversed().find((msg) => msg.role === "user");
5344
5337
  if (!lastUserMessageBeforeRegenerate) historyCutoff = [messages[0]];
5345
5338
  else {
5346
5339
  const indexOfLastUserMessageBeforeRegenerate = messages.findIndex((msg) => msg.id === lastUserMessageBeforeRegenerate.id);
@@ -6472,6 +6465,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6472
6465
  },
6473
6466
  onRunFinishedEvent: () => {
6474
6467
  nodeNameRef.current = "end";
6468
+ },
6469
+ onRunErrorEvent: () => {
6470
+ nodeNameRef.current = "end";
6475
6471
  }
6476
6472
  });
6477
6473
  return () => {
@@ -7124,7 +7120,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7124
7120
  * @param data The data to use for the task.
7125
7121
  */
7126
7122
  async run(context, data) {
7127
- var _this$forwardedParame, _response$data;
7123
+ var _response$data;
7128
7124
  const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
7129
7125
  for (const fn of this.actions) actions[fn.name] = fn;
7130
7126
  let contextString = "";
@@ -7149,7 +7145,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7149
7145
  metadata: { requestType: _copilotkit_runtime_client_gql.CopilotRequestType.Task },
7150
7146
  forwardedParameters: {
7151
7147
  toolChoice: "required",
7152
- ...(_this$forwardedParame = this.forwardedParameters) !== null && _this$forwardedParame !== void 0 ? _this$forwardedParame : {}
7148
+ ...this.forwardedParameters
7153
7149
  }
7154
7150
  },
7155
7151
  properties: context.copilotApiConfig.properties