@copilotkit/core 1.79.0 → 1.79.1-canary.1792089208

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
@@ -23,7 +23,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
23
23
 
24
24
  //#endregion
25
25
  //#region src/utils/connect-replay.ts
26
- /**
26
+ const connectRunErrorPhases = /* @__PURE__ */ new WeakMap();
27
+ /**
28
+ * The phase in which a connection received `event`, as recorded when it
29
+ * arrived. Events that did not come through a connection with replay
30
+ * boundaries report `unknown`.
31
+ */
32
+ function ɵgetConnectRunErrorPhase(event) {
33
+ var _connectRunErrorPhase;
34
+ return (_connectRunErrorPhase = connectRunErrorPhases.get(event)) !== null && _connectRunErrorPhase !== void 0 ? _connectRunErrorPhase : "unknown";
35
+ }
36
+ /**
27
37
  * Runs an agent's `connect()` stream through the AbstractAgent apply pipeline
28
38
  * with the `verifyEvents` step omitted.
29
39
  *
@@ -78,6 +88,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
78
88
  let result;
79
89
  const previousMessageIds = new Set(agent.messages.map((m) => m.id));
80
90
  let isReplaying = true;
91
+ let reportsReplayPhase = false;
81
92
  const liveErrors = /* @__PURE__ */ new WeakSet();
82
93
  const subscribers = [
83
94
  {
@@ -125,15 +136,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
125
136
  };
126
137
  const lifecycle = {
127
138
  onReplayStarted: () => {
139
+ reportsReplayPhase = true;
128
140
  isReplaying = true;
129
141
  agent.isRunning = true;
130
142
  },
131
143
  onReplayFinished: () => {
144
+ reportsReplayPhase = true;
132
145
  isReplaying = false;
133
146
  }
134
147
  };
135
148
  const source$ = (0, rxjs.defer)(() => new _ag_ui_client.CompatibilityBoundary().run(input, { run: () => connect ? connect(input, lifecycle) : self.connect(input) })).pipe((0, rxjs_operators.tap)((event) => {
136
- if (!isReplaying && event.type === _ag_ui_client.EventType.RUN_ERROR) liveErrors.add(event);
149
+ if (event.type !== _ag_ui_client.EventType.RUN_ERROR) return;
150
+ if (!isReplaying) liveErrors.add(event);
151
+ if (reportsReplayPhase) connectRunErrorPhases.set(event, isReplaying ? "replay" : "live");
137
152
  }), (0, _ag_ui_client.transformChunks)(self.debugLogger), (0, rxjs_operators.takeUntil)(activeRunDetach$));
138
153
  const applied$ = self.apply(input, source$, subscribers);
139
154
  await (0, rxjs.lastValueFrom)(self.processApplyEvents(input, applied$, subscribers).pipe((0, rxjs_operators.catchError)((error) => {
@@ -342,6 +357,20 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
342
357
  }
343
358
  };
344
359
  /**
360
+ * The gateway could not replay a live run's events, so the client cannot
361
+ * verify the run it is following. The run itself may still be going on the
362
+ * server; reconnecting to the thread shows its real state.
363
+ */
364
+ var IntelligenceReplayFailedError = class extends Error {
365
+ constructor(threadId, runId) {
366
+ super("The run's events could not be replayed. Reconnect to the thread to check the run's status.");
367
+ this.threadId = threadId;
368
+ this.runId = runId;
369
+ _defineProperty(this, "code", "INTELLIGENCE_REPLAY_FAILED");
370
+ this.name = "IntelligenceReplayFailedError";
371
+ }
372
+ };
373
+ /**
345
374
  * Type guard for {@link RunCompletionAware}. Returns true when `agent` exposes
346
375
  * an `activeRunCompletionPromise` property, so callers can await an in-flight
347
376
  * run without an `as unknown as` cast. Returns false for agents that don't
@@ -672,6 +701,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
672
701
  };
673
702
  const replayFailed$ = channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), (0, rxjs_operators.tap)(() => {
674
703
  controlCursor.replayFailed = true;
704
+ if (options.streamMode === "run") throw new IntelligenceReplayFailedError(credentials.threadId, credentials.runId);
675
705
  }));
676
706
  const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe((0, rxjs_operators.tap)(() => {
677
707
  var _options$lifecycle2, _options$lifecycle2$o;
@@ -3873,7 +3903,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3873
3903
  forwardedProps: this._internal.properties,
3874
3904
  tools: this.buildFrontendTools(agent.agentId),
3875
3905
  context: this._internal.getContextForAgent(agent.agentId)
3876
- }, this.createAgentErrorSubscriber(agent));
3906
+ }, this.createAgentErrorSubscriber(agent, "connect"));
3877
3907
  if (this._connectionGenerations.get(agent) !== connection || ((_agent$threadId4 = agent.threadId) !== null && _agent$threadId4 !== void 0 ? _agent$threadId4 : null) !== incomingThreadId) return runAgentResult;
3878
3908
  const controller = new AbortController();
3879
3909
  const replay = (_this$_interactionAbo = this._interactionAbortControllers.get(agent)) !== null && _this$_interactionAbo !== void 0 ? _this$_interactionAbo : {
@@ -3967,7 +3997,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3967
3997
  this._runDepth++;
3968
3998
  try {
3969
3999
  let logicalRunId = resumedRunId !== null && resumedRunId !== void 0 ? resumedRunId : runId;
3970
- const agentSubscriber = this.createAgentErrorSubscriber(agent);
4000
+ const agentSubscriber = this.createAgentErrorSubscriber(agent, "run");
3971
4001
  let started = false;
3972
4002
  const onRunStartedEvent = agentSubscriber.onRunStartedEvent;
3973
4003
  const onRunInitialized = agentSubscriber.onRunInitialized;
@@ -4501,7 +4531,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4501
4531
  /**
4502
4532
  * Create an agent error subscriber
4503
4533
  */
4504
- createAgentErrorSubscriber(agent) {
4534
+ createAgentErrorSubscriber(agent, stream) {
4505
4535
  const emitAgentError = async (error, code, extraContext = {}) => {
4506
4536
  const context = { ...extraContext };
4507
4537
  if (agent.agentId) context.agentId = agent.agentId;
@@ -4525,7 +4555,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4525
4555
  await emitAgentError(rawError, CopilotKitCoreErrorCode.AGENT_RUN_ERROR_EVENT, {
4526
4556
  source: "onRunErrorEvent",
4527
4557
  event,
4528
- runtimeErrorCode: event === null || event === void 0 ? void 0 : event.code
4558
+ runtimeErrorCode: event === null || event === void 0 ? void 0 : event.code,
4559
+ phase: stream === "run" ? "live" : ɵgetConnectRunErrorPhase(event)
4529
4560
  });
4530
4561
  }
4531
4562
  };
@@ -5641,7 +5672,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5641
5672
  });
5642
5673
  }
5643
5674
  if (config.sink === void 0) {
5644
- if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
5675
+ if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture ignores it; assign Learning Spaces on the server with getTrajectoryLearningContainerIds on CopilotKitIntelligence, and remove learningContainerIds from the capture options.");
5645
5676
  this.stopLegacy();
5646
5677
  return this.connection.start(options.trajectoryId, config);
5647
5678
  }
@@ -6969,6 +7000,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6969
7000
  CopilotKitCoreErrorCode["AGENT_CONNECT_FAILED"] = "agent_connect_failed";
6970
7001
  CopilotKitCoreErrorCode["AGENT_RUN_FAILED"] = "agent_run_failed";
6971
7002
  CopilotKitCoreErrorCode["AGENT_RUN_FAILED_EVENT"] = "agent_run_failed_event";
7003
+ /**
7004
+ * An agent emitted RUN_ERROR. `context.phase` (`RunErrorPhase`) is
7005
+ * `"replay"` when the error belongs to stored thread history replayed on
7006
+ * connect, `"live"` when the run is happening now, and `"unknown"` when the
7007
+ * transport cannot tell. Show a live-failure notice only for `"live"`.
7008
+ */
6972
7009
  CopilotKitCoreErrorCode["AGENT_RUN_ERROR_EVENT"] = "agent_run_error_event";
6973
7010
  CopilotKitCoreErrorCode["TOOL_ARGUMENT_PARSE_FAILED"] = "tool_argument_parse_failed";
6974
7011
  CopilotKitCoreErrorCode["TOOL_HANDLER_FAILED"] = "tool_handler_failed";
@@ -9093,6 +9130,7 @@ exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionS
9093
9130
  exports.CopilotKitHeaderResolutionError = CopilotKitHeaderResolutionError;
9094
9131
  exports.INSPECTOR_THREAD_BRIDGE_PLUGIN_ID = INSPECTOR_THREAD_BRIDGE_PLUGIN_ID;
9095
9132
  exports.IntelligenceAgent = IntelligenceAgent;
9133
+ exports.IntelligenceReplayFailedError = IntelligenceReplayFailedError;
9096
9134
  exports.MEMORY_ERROR_REGISTRY = MEMORY_ERROR_REGISTRY;
9097
9135
  exports.MemoryError = MemoryError;
9098
9136
  exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;