@copilotkit/runtime 1.9.1-next.0 → 1.9.2-next.0
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/CHANGELOG.md +19 -0
- package/dist/{chunk-MKAQQQ7D.mjs → chunk-44FYLJJJ.mjs} +2 -2
- package/dist/{chunk-T3HIFVU2.mjs → chunk-ESXPDYNT.mjs} +2 -2
- package/dist/{chunk-32OC2CBT.mjs → chunk-O6KXX5R5.mjs} +2 -2
- package/dist/{chunk-YVZCIKZM.mjs → chunk-YMIOUUPV.mjs} +260 -61
- package/dist/chunk-YMIOUUPV.mjs.map +1 -0
- package/dist/{chunk-5CY2MEHT.mjs → chunk-YXL4PSJM.mjs} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +305 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +298 -99
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +16 -7
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +16 -7
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +16 -7
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +16 -7
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/{shared-0c31d7c5.d.ts → shared-e272b15a.d.ts} +1 -0
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +10 -1
- package/src/graphql/resolvers/copilot.resolver.ts +13 -0
- package/src/graphql/resolvers/state.resolver.ts +5 -7
- package/src/lib/runtime/copilot-runtime.ts +62 -6
- package/src/lib/runtime/remote-action-constructors.ts +37 -28
- package/src/lib/runtime/remote-lg-action.ts +45 -24
- package/src/lib/runtime/retry-utils.ts +96 -0
- package/src/lib/streaming.ts +54 -1
- package/src/service-adapters/events.ts +101 -6
- package/dist/chunk-YVZCIKZM.mjs.map +0 -1
- /package/dist/{chunk-MKAQQQ7D.mjs.map → chunk-44FYLJJJ.mjs.map} +0 -0
- /package/dist/{chunk-T3HIFVU2.mjs.map → chunk-ESXPDYNT.mjs.map} +0 -0
- /package/dist/{chunk-32OC2CBT.mjs.map → chunk-O6KXX5R5.mjs.map} +0 -0
- /package/dist/{chunk-5CY2MEHT.mjs.map → chunk-YXL4PSJM.mjs.map} +0 -0
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Action,
|
|
3
|
+
randomId,
|
|
4
|
+
CopilotKitError,
|
|
5
|
+
CopilotKitErrorCode,
|
|
6
|
+
CopilotKitLowLevelError,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
2
8
|
import {
|
|
3
9
|
of,
|
|
4
10
|
concat,
|
|
@@ -10,14 +16,22 @@ import {
|
|
|
10
16
|
from,
|
|
11
17
|
catchError,
|
|
12
18
|
EMPTY,
|
|
19
|
+
BehaviorSubject,
|
|
13
20
|
} from "rxjs";
|
|
14
21
|
import { streamLangChainResponse } from "./langchain/utils";
|
|
15
22
|
import { GuardrailsResult } from "../graphql/types/guardrails-result.type";
|
|
16
23
|
import telemetry from "../lib/telemetry-client";
|
|
17
24
|
import { isRemoteAgentAction } from "../lib/runtime/remote-actions";
|
|
18
25
|
import { ActionInput } from "../graphql/inputs/action.input";
|
|
19
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
ActionExecutionMessage,
|
|
28
|
+
ResultMessage,
|
|
29
|
+
TextMessage,
|
|
30
|
+
Message,
|
|
31
|
+
} from "../graphql/types/converted";
|
|
20
32
|
import { plainToInstance } from "class-transformer";
|
|
33
|
+
import { MessageRole } from "../graphql/types/enums";
|
|
34
|
+
import { parseJson, tryMap } from "@copilotkit/shared";
|
|
21
35
|
|
|
22
36
|
export enum RuntimeEventTypes {
|
|
23
37
|
TextMessageStart = "TextMessageStart",
|
|
@@ -260,7 +274,10 @@ export class RuntimeEventSource {
|
|
|
260
274
|
}) {
|
|
261
275
|
this.callback(this.eventStream$).catch((error) => {
|
|
262
276
|
console.error("Error in event source callback", error);
|
|
263
|
-
|
|
277
|
+
|
|
278
|
+
// Convert streaming errors to structured errors
|
|
279
|
+
const structuredError = convertStreamingErrorToStructured(error);
|
|
280
|
+
this.eventStream$.error(structuredError);
|
|
264
281
|
this.eventStream$.complete();
|
|
265
282
|
});
|
|
266
283
|
return this.eventStream$.pipe(
|
|
@@ -321,7 +338,18 @@ export class RuntimeEventSource {
|
|
|
321
338
|
return concat(of(eventWithState.event!), toolCallEventStream$).pipe(
|
|
322
339
|
catchError((error) => {
|
|
323
340
|
console.error("Error in tool call stream", error);
|
|
324
|
-
|
|
341
|
+
|
|
342
|
+
// Convert streaming errors to structured errors and send as action result
|
|
343
|
+
const structuredError = convertStreamingErrorToStructured(error);
|
|
344
|
+
toolCallEventStream$.sendActionExecutionResult({
|
|
345
|
+
actionExecutionId: eventWithState.actionExecutionId!,
|
|
346
|
+
actionName: eventWithState.action!.name,
|
|
347
|
+
error: {
|
|
348
|
+
code: structuredError.code,
|
|
349
|
+
message: structuredError.message,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
|
|
325
353
|
return EMPTY;
|
|
326
354
|
}),
|
|
327
355
|
);
|
|
@@ -409,12 +437,15 @@ async function executeAction(
|
|
|
409
437
|
next: (event) => eventStream$.next(event),
|
|
410
438
|
error: (err) => {
|
|
411
439
|
console.error("Error in stream", err);
|
|
440
|
+
|
|
441
|
+
// Convert streaming errors to structured errors
|
|
442
|
+
const structuredError = convertStreamingErrorToStructured(err);
|
|
412
443
|
eventStream$.sendActionExecutionResult({
|
|
413
444
|
actionExecutionId,
|
|
414
445
|
actionName: action.name,
|
|
415
446
|
error: {
|
|
416
|
-
code:
|
|
417
|
-
message:
|
|
447
|
+
code: structuredError.code,
|
|
448
|
+
message: structuredError.message,
|
|
418
449
|
},
|
|
419
450
|
});
|
|
420
451
|
eventStream$.complete();
|
|
@@ -447,3 +478,67 @@ async function executeAction(
|
|
|
447
478
|
}
|
|
448
479
|
}
|
|
449
480
|
}
|
|
481
|
+
|
|
482
|
+
function convertStreamingErrorToStructured(error: any): CopilotKitError {
|
|
483
|
+
// Handle network termination errors
|
|
484
|
+
if (
|
|
485
|
+
error?.message?.includes("terminated") ||
|
|
486
|
+
error?.cause?.code === "UND_ERR_SOCKET" ||
|
|
487
|
+
error?.message?.includes("other side closed") ||
|
|
488
|
+
error?.code === "UND_ERR_SOCKET"
|
|
489
|
+
) {
|
|
490
|
+
return new CopilotKitError({
|
|
491
|
+
message:
|
|
492
|
+
"Connection to agent was unexpectedly terminated. This may be due to the agent service being restarted or network issues. Please try again.",
|
|
493
|
+
code: CopilotKitErrorCode.NETWORK_ERROR,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Handle other network-related errors
|
|
498
|
+
if (
|
|
499
|
+
error?.message?.includes("fetch failed") ||
|
|
500
|
+
error?.message?.includes("ECONNREFUSED") ||
|
|
501
|
+
error?.message?.includes("ENOTFOUND") ||
|
|
502
|
+
error?.message?.includes("ETIMEDOUT")
|
|
503
|
+
) {
|
|
504
|
+
return new CopilotKitLowLevelError({
|
|
505
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
506
|
+
url: "event streaming connection",
|
|
507
|
+
message:
|
|
508
|
+
"Network error occurred during event streaming. Please check your connection and try again.",
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Handle abort/cancellation errors (these are usually normal)
|
|
513
|
+
if (
|
|
514
|
+
error?.message?.includes("aborted") ||
|
|
515
|
+
error?.message?.includes("canceled") ||
|
|
516
|
+
error?.message?.includes("signal is aborted")
|
|
517
|
+
) {
|
|
518
|
+
return new CopilotKitError({
|
|
519
|
+
message: "Request was cancelled",
|
|
520
|
+
code: CopilotKitErrorCode.UNKNOWN,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Handle API key errors (authentication/authorization issues)
|
|
525
|
+
const errorMessage = error?.message || String(error);
|
|
526
|
+
if (
|
|
527
|
+
errorMessage.includes("401") ||
|
|
528
|
+
errorMessage.toLowerCase().includes("api key") ||
|
|
529
|
+
errorMessage.toLowerCase().includes("unauthorized") ||
|
|
530
|
+
errorMessage.toLowerCase().includes("authentication") ||
|
|
531
|
+
errorMessage.toLowerCase().includes("incorrect api key")
|
|
532
|
+
) {
|
|
533
|
+
return new CopilotKitError({
|
|
534
|
+
message: `Event streaming error: ${errorMessage}`,
|
|
535
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Default: convert unknown streaming errors
|
|
540
|
+
return new CopilotKitError({
|
|
541
|
+
message: `Event streaming error: ${errorMessage}`,
|
|
542
|
+
code: CopilotKitErrorCode.UNKNOWN,
|
|
543
|
+
});
|
|
544
|
+
}
|