@copilotkit/core 1.79.0 → 1.79.1-canary.1792034358
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 +43 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +26 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +43 -7
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +45 -7
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,15 @@ function ɵisHttpAgent(agent) {
|
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
28
|
//#region src/utils/connect-replay.ts
|
|
29
|
+
const connectRunErrorPhases = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
/**
|
|
31
|
+
* The phase in which a connection received `event`, as recorded when it
|
|
32
|
+
* arrived. Events that did not come through a connection with replay
|
|
33
|
+
* boundaries report `unknown`.
|
|
34
|
+
*/
|
|
35
|
+
function ɵgetConnectRunErrorPhase(event) {
|
|
36
|
+
return connectRunErrorPhases.get(event) ?? "unknown";
|
|
37
|
+
}
|
|
29
38
|
/**
|
|
30
39
|
* Runs an agent's `connect()` stream through the AbstractAgent apply pipeline
|
|
31
40
|
* with the `verifyEvents` step omitted.
|
|
@@ -80,6 +89,7 @@ async function ɵconnectWithoutEventVerification(agent, parameters, subscriber,
|
|
|
80
89
|
let result;
|
|
81
90
|
const previousMessageIds = new Set(agent.messages.map((m) => m.id));
|
|
82
91
|
let isReplaying = true;
|
|
92
|
+
let reportsReplayPhase = false;
|
|
83
93
|
const liveErrors = /* @__PURE__ */ new WeakSet();
|
|
84
94
|
const subscribers = [
|
|
85
95
|
{
|
|
@@ -127,15 +137,19 @@ async function ɵconnectWithoutEventVerification(agent, parameters, subscriber,
|
|
|
127
137
|
};
|
|
128
138
|
const lifecycle = {
|
|
129
139
|
onReplayStarted: () => {
|
|
140
|
+
reportsReplayPhase = true;
|
|
130
141
|
isReplaying = true;
|
|
131
142
|
agent.isRunning = true;
|
|
132
143
|
},
|
|
133
144
|
onReplayFinished: () => {
|
|
145
|
+
reportsReplayPhase = true;
|
|
134
146
|
isReplaying = false;
|
|
135
147
|
}
|
|
136
148
|
};
|
|
137
149
|
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) => {
|
|
138
|
-
if (
|
|
150
|
+
if (event.type !== _ag_ui_client.EventType.RUN_ERROR) return;
|
|
151
|
+
if (!isReplaying) liveErrors.add(event);
|
|
152
|
+
if (reportsReplayPhase) connectRunErrorPhases.set(event, isReplaying ? "replay" : "live");
|
|
139
153
|
}), (0, _ag_ui_client.transformChunks)(self.debugLogger), (0, rxjs_operators.takeUntil)(activeRunDetach$));
|
|
140
154
|
const applied$ = self.apply(input, source$, subscribers);
|
|
141
155
|
await (0, rxjs.lastValueFrom)(self.processApplyEvents(input, applied$, subscribers).pipe((0, rxjs_operators.catchError)((error) => {
|
|
@@ -302,6 +316,20 @@ var AgentThreadLockedError = class extends Error {
|
|
|
302
316
|
}
|
|
303
317
|
};
|
|
304
318
|
/**
|
|
319
|
+
* The gateway could not replay a live run's events, so the client cannot
|
|
320
|
+
* verify the run it is following. The run itself may still be going on the
|
|
321
|
+
* server; reconnecting to the thread shows its real state.
|
|
322
|
+
*/
|
|
323
|
+
var IntelligenceReplayFailedError = class extends Error {
|
|
324
|
+
code = "INTELLIGENCE_REPLAY_FAILED";
|
|
325
|
+
constructor(threadId, runId) {
|
|
326
|
+
super("The run's events could not be replayed. Reconnect to the thread to check the run's status.");
|
|
327
|
+
this.threadId = threadId;
|
|
328
|
+
this.runId = runId;
|
|
329
|
+
this.name = "IntelligenceReplayFailedError";
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
305
333
|
* Type guard for {@link RunCompletionAware}. Returns true when `agent` exposes
|
|
306
334
|
* an `activeRunCompletionPromise` property, so callers can await an in-flight
|
|
307
335
|
* run without an `as unknown as` cast. Returns false for agents that don't
|
|
@@ -627,6 +655,7 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
|
|
|
627
655
|
};
|
|
628
656
|
const replayFailed$ = channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), (0, rxjs_operators.tap)(() => {
|
|
629
657
|
controlCursor.replayFailed = true;
|
|
658
|
+
if (options.streamMode === "run") throw new IntelligenceReplayFailedError(credentials.threadId, credentials.runId);
|
|
630
659
|
}));
|
|
631
660
|
const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe((0, rxjs_operators.tap)(() => {
|
|
632
661
|
replayFinished = true;
|
|
@@ -3787,7 +3816,7 @@ var RunHandler = class {
|
|
|
3787
3816
|
forwardedProps: this._internal.properties,
|
|
3788
3817
|
tools: this.buildFrontendTools(agent.agentId),
|
|
3789
3818
|
context: this._internal.getContextForAgent(agent.agentId)
|
|
3790
|
-
}, this.createAgentErrorSubscriber(agent));
|
|
3819
|
+
}, this.createAgentErrorSubscriber(agent, "connect"));
|
|
3791
3820
|
if (this._connectionGenerations.get(agent) !== connection || (agent.threadId ?? null) !== incomingThreadId) return runAgentResult;
|
|
3792
3821
|
const controller = new AbortController();
|
|
3793
3822
|
const replay = this._interactionAbortControllers.get(agent) ?? {
|
|
@@ -3878,7 +3907,7 @@ var RunHandler = class {
|
|
|
3878
3907
|
this._runDepth++;
|
|
3879
3908
|
try {
|
|
3880
3909
|
let logicalRunId = resumedRunId ?? runId;
|
|
3881
|
-
const agentSubscriber = this.createAgentErrorSubscriber(agent);
|
|
3910
|
+
const agentSubscriber = this.createAgentErrorSubscriber(agent, "run");
|
|
3882
3911
|
let started = false;
|
|
3883
3912
|
const onRunStartedEvent = agentSubscriber.onRunStartedEvent;
|
|
3884
3913
|
const onRunInitialized = agentSubscriber.onRunInitialized;
|
|
@@ -4383,7 +4412,7 @@ var RunHandler = class {
|
|
|
4383
4412
|
/**
|
|
4384
4413
|
* Create an agent error subscriber
|
|
4385
4414
|
*/
|
|
4386
|
-
createAgentErrorSubscriber(agent) {
|
|
4415
|
+
createAgentErrorSubscriber(agent, stream) {
|
|
4387
4416
|
const emitAgentError = async (error, code, extraContext = {}) => {
|
|
4388
4417
|
const context = { ...extraContext };
|
|
4389
4418
|
if (agent.agentId) context.agentId = agent.agentId;
|
|
@@ -4406,7 +4435,8 @@ var RunHandler = class {
|
|
|
4406
4435
|
await emitAgentError(rawError, CopilotKitCoreErrorCode.AGENT_RUN_ERROR_EVENT, {
|
|
4407
4436
|
source: "onRunErrorEvent",
|
|
4408
4437
|
event,
|
|
4409
|
-
runtimeErrorCode: event?.code
|
|
4438
|
+
runtimeErrorCode: event?.code,
|
|
4439
|
+
phase: stream === "run" ? "live" : ɵgetConnectRunErrorPhase(event)
|
|
4410
4440
|
});
|
|
4411
4441
|
}
|
|
4412
4442
|
};
|
|
@@ -5462,7 +5492,7 @@ var LearningBridge = class {
|
|
|
5462
5492
|
});
|
|
5463
5493
|
}
|
|
5464
5494
|
if (config.sink === void 0) {
|
|
5465
|
-
if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture
|
|
5495
|
+
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.");
|
|
5466
5496
|
this.stopLegacy();
|
|
5467
5497
|
return this.connection.start(options.trajectoryId, config);
|
|
5468
5498
|
}
|
|
@@ -6771,6 +6801,12 @@ let CopilotKitCoreErrorCode = /* @__PURE__ */ function(CopilotKitCoreErrorCode)
|
|
|
6771
6801
|
CopilotKitCoreErrorCode["AGENT_CONNECT_FAILED"] = "agent_connect_failed";
|
|
6772
6802
|
CopilotKitCoreErrorCode["AGENT_RUN_FAILED"] = "agent_run_failed";
|
|
6773
6803
|
CopilotKitCoreErrorCode["AGENT_RUN_FAILED_EVENT"] = "agent_run_failed_event";
|
|
6804
|
+
/**
|
|
6805
|
+
* An agent emitted RUN_ERROR. `context.phase` (`RunErrorPhase`) is
|
|
6806
|
+
* `"replay"` when the error belongs to stored thread history replayed on
|
|
6807
|
+
* connect, `"live"` when the run is happening now, and `"unknown"` when the
|
|
6808
|
+
* transport cannot tell. Show a live-failure notice only for `"live"`.
|
|
6809
|
+
*/
|
|
6774
6810
|
CopilotKitCoreErrorCode["AGENT_RUN_ERROR_EVENT"] = "agent_run_error_event";
|
|
6775
6811
|
CopilotKitCoreErrorCode["TOOL_ARGUMENT_PARSE_FAILED"] = "tool_argument_parse_failed";
|
|
6776
6812
|
CopilotKitCoreErrorCode["TOOL_HANDLER_FAILED"] = "tool_handler_failed";
|
|
@@ -8841,6 +8877,7 @@ exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionS
|
|
|
8841
8877
|
exports.CopilotKitHeaderResolutionError = CopilotKitHeaderResolutionError;
|
|
8842
8878
|
exports.INSPECTOR_THREAD_BRIDGE_PLUGIN_ID = INSPECTOR_THREAD_BRIDGE_PLUGIN_ID;
|
|
8843
8879
|
exports.IntelligenceAgent = IntelligenceAgent;
|
|
8880
|
+
exports.IntelligenceReplayFailedError = IntelligenceReplayFailedError;
|
|
8844
8881
|
exports.MEMORY_ERROR_REGISTRY = MEMORY_ERROR_REGISTRY;
|
|
8845
8882
|
exports.MemoryError = MemoryError;
|
|
8846
8883
|
exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
|