@copilotkit/core 1.79.1-canary.1792091124 → 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.
package/dist/index.cjs CHANGED
@@ -3480,6 +3480,17 @@ var WebMCPRegistry = class {
3480
3480
  * takes no reason and whose signals never expose one.
3481
3481
  */
3482
3482
  const liveHITLStops = /* @__PURE__ */ new WeakMap();
3483
+ /**
3484
+ * Edits `agent.messages` by replacing the array instead of changing it in
3485
+ * place. The current array may be the one the agent emitted with its last
3486
+ * update, which subscribers and stored snapshots still hold. Like the in-place
3487
+ * edit it replaces, this notifies no subscriber.
3488
+ */
3489
+ function editAgentMessages(agent, edit) {
3490
+ const messages = [...agent.messages];
3491
+ edit(messages);
3492
+ agent.messages = messages;
3493
+ }
3483
3494
  function discardAbortedResult(signal, discardOnAbort, errorMessage) {
3484
3495
  return !!(discardOnAbort && signal?.aborted && !(liveHITLStops.get(signal)?.() && errorMessage));
3485
3496
  }
@@ -3994,7 +4005,7 @@ var RunHandler = class {
3994
4005
  if (existingResultIndex !== -1) newMessages.splice(existingResultIndex, 1);
3995
4006
  existingResult = void 0;
3996
4007
  const agentMsgIdx = agent.messages.findIndex((m) => m.role === "tool" && m.toolCallId === toolCall.id);
3997
- if (agentMsgIdx !== -1) agent.messages.splice(agentMsgIdx, 1);
4008
+ if (agentMsgIdx !== -1) editAgentMessages(agent, (messages) => messages.splice(agentMsgIdx, 1));
3998
4009
  }
3999
4010
  if (!existingResult) {
4000
4011
  executing.add(executionKey);
@@ -4164,7 +4175,7 @@ var RunHandler = class {
4164
4175
  toolCallId: toolCall.id,
4165
4176
  content: handlerResult.content
4166
4177
  };
4167
- agent.messages.splice(insertAt, 0, toolMessage);
4178
+ editAgentMessages(agent, (messages) => messages.splice(insertAt, 0, toolMessage));
4168
4179
  if (!handlerResult.error && tool?.followUp !== false) return true;
4169
4180
  }
4170
4181
  return false;
@@ -4257,7 +4268,7 @@ var RunHandler = class {
4257
4268
  toolCallId: toolCall.id,
4258
4269
  content: toolCallResult
4259
4270
  };
4260
- agent.messages.splice(insertAt, 0, toolMessage);
4271
+ editAgentMessages(agent, (messages) => messages.splice(insertAt, 0, toolMessage));
4261
4272
  if (!errorMessage && wildcardTool?.followUp !== false) return true;
4262
4273
  }
4263
4274
  return false;
@@ -4311,7 +4322,7 @@ var RunHandler = class {
4311
4322
  content: "",
4312
4323
  toolCalls: [assistantToolCall]
4313
4324
  };
4314
- agent.messages.push(assistantMessage);
4325
+ editAgentMessages(agent, (messages) => messages.push(assistantMessage));
4315
4326
  let handlerResult = {
4316
4327
  content: "",
4317
4328
  result: "",
@@ -4333,8 +4344,8 @@ var RunHandler = class {
4333
4344
  content: handlerResult.content
4334
4345
  };
4335
4346
  const assistantIndex = agent.messages.findIndex((m) => m.id === assistantMessage.id);
4336
- if (assistantIndex !== -1) agent.messages.splice(assistantIndex + 1, 0, toolResultMessage);
4337
- else agent.messages.push(toolResultMessage);
4347
+ if (assistantIndex !== -1) editAgentMessages(agent, (messages) => messages.splice(assistantIndex + 1, 0, toolResultMessage));
4348
+ else editAgentMessages(agent, (messages) => messages.push(toolResultMessage));
4338
4349
  if (!handlerResult.error && followUp !== false) {
4339
4350
  if (typeof followUp === "string" && followUp !== "generate") {
4340
4351
  const userMessage = {
@@ -4342,7 +4353,7 @@ var RunHandler = class {
4342
4353
  role: "user",
4343
4354
  content: followUp
4344
4355
  };
4345
- agent.messages.push(userMessage);
4356
+ editAgentMessages(agent, (messages) => messages.push(userMessage));
4346
4357
  }
4347
4358
  await this._internal.waitForPendingFrameworkUpdates();
4348
4359
  await this.runAgent({ agent });