@copilotkit/runtime 1.9.2-next.7 → 1.9.2-next.9

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-IIXJVVTV.mjs → chunk-4JBKY7XT.mjs} +109 -75
  3. package/dist/chunk-4JBKY7XT.mjs.map +1 -0
  4. package/dist/{chunk-LSB3QZHS.mjs → chunk-5YGKE5SN.mjs} +2 -2
  5. package/dist/{chunk-2PQGAIVB.mjs → chunk-ALZ5H3VD.mjs} +2 -2
  6. package/dist/chunk-AMUJQ6IR.mjs +50 -0
  7. package/dist/chunk-AMUJQ6IR.mjs.map +1 -0
  8. package/dist/{chunk-2UAJCT5X.mjs → chunk-SMDVD4VG.mjs} +2 -2
  9. package/dist/{chunk-GW6ERFKI.mjs → chunk-UUXRYAB4.mjs} +2 -2
  10. package/dist/{chunk-5BIEM2UU.mjs → chunk-XWBDEXDA.mjs} +4 -3
  11. package/dist/{chunk-5BIEM2UU.mjs.map → chunk-XWBDEXDA.mjs.map} +1 -1
  12. package/dist/{chunk-HB4D2KJC.mjs → chunk-Z5GYTKMD.mjs} +2345 -2066
  13. package/dist/chunk-Z5GYTKMD.mjs.map +1 -0
  14. package/dist/{groq-adapter-25a2bd35.d.ts → groq-adapter-172a2ca4.d.ts} +1 -1
  15. package/dist/index.d.ts +4 -3
  16. package/dist/index.js +3713 -3356
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +12 -8
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/lib/index.d.ts +3 -3
  21. package/dist/lib/index.js +2981 -2624
  22. package/dist/lib/index.js.map +1 -1
  23. package/dist/lib/index.mjs +9 -8
  24. package/dist/lib/integrations/index.d.ts +3 -3
  25. package/dist/lib/integrations/index.js +141 -86
  26. package/dist/lib/integrations/index.js.map +1 -1
  27. package/dist/lib/integrations/index.mjs +7 -6
  28. package/dist/lib/integrations/nest/index.d.ts +2 -2
  29. package/dist/lib/integrations/nest/index.js +141 -86
  30. package/dist/lib/integrations/nest/index.js.map +1 -1
  31. package/dist/lib/integrations/nest/index.mjs +5 -4
  32. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  33. package/dist/lib/integrations/node-express/index.js +141 -86
  34. package/dist/lib/integrations/node-express/index.js.map +1 -1
  35. package/dist/lib/integrations/node-express/index.mjs +5 -4
  36. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  37. package/dist/lib/integrations/node-http/index.js +141 -86
  38. package/dist/lib/integrations/node-http/index.js.map +1 -1
  39. package/dist/lib/integrations/node-http/index.mjs +4 -3
  40. package/dist/service-adapters/index.d.ts +5 -4
  41. package/dist/service-adapters/index.js +179 -104
  42. package/dist/service-adapters/index.js.map +1 -1
  43. package/dist/service-adapters/index.mjs +6 -2
  44. package/dist/service-adapters/shared/index.d.ts +9 -0
  45. package/dist/service-adapters/shared/index.js +72 -0
  46. package/dist/service-adapters/shared/index.js.map +1 -0
  47. package/dist/service-adapters/shared/index.mjs +8 -0
  48. package/dist/service-adapters/shared/index.mjs.map +1 -0
  49. package/dist/{shared-941d59dc.d.ts → shared-bd953ebf.d.ts} +8 -4
  50. package/dist/utils/index.d.ts +17 -1
  51. package/dist/utils/index.js +3 -2
  52. package/dist/utils/index.js.map +1 -1
  53. package/dist/utils/index.mjs +1 -1
  54. package/package.json +2 -2
  55. package/src/agents/langgraph/event-source.ts +36 -38
  56. package/src/agents/langgraph/events.ts +19 -1
  57. package/src/graphql/resolvers/copilot.resolver.ts +84 -40
  58. package/src/lib/error-messages.ts +200 -0
  59. package/src/lib/integrations/shared.ts +43 -0
  60. package/src/lib/runtime/copilot-runtime.ts +56 -48
  61. package/src/lib/runtime/remote-action-constructors.ts +28 -3
  62. package/src/lib/runtime/remote-lg-action.ts +130 -40
  63. package/src/lib/streaming.ts +125 -36
  64. package/src/service-adapters/anthropic/anthropic-adapter.ts +3 -4
  65. package/src/service-adapters/events.ts +37 -81
  66. package/src/service-adapters/groq/groq-adapter.ts +66 -56
  67. package/src/service-adapters/index.ts +1 -0
  68. package/src/service-adapters/openai/openai-adapter.ts +18 -3
  69. package/src/service-adapters/shared/error-utils.ts +61 -0
  70. package/src/service-adapters/shared/index.ts +1 -0
  71. package/src/utils/failed-response-status-reasons.ts +23 -1
  72. package/dist/chunk-HB4D2KJC.mjs.map +0 -1
  73. package/dist/chunk-IIXJVVTV.mjs.map +0 -1
  74. package/dist/{chunk-LSB3QZHS.mjs.map → chunk-5YGKE5SN.mjs.map} +0 -0
  75. package/dist/{chunk-2PQGAIVB.mjs.map → chunk-ALZ5H3VD.mjs.map} +0 -0
  76. package/dist/{chunk-2UAJCT5X.mjs.map → chunk-SMDVD4VG.mjs.map} +0 -0
  77. package/dist/{chunk-GW6ERFKI.mjs.map → chunk-UUXRYAB4.mjs.map} +0 -0
  78. package/dist/{langserve-4a5c9217.d.ts → langserve-fc5cac89.d.ts} +7 -7
@@ -11,7 +11,10 @@ import {
11
11
  OpenAIAssistantAdapter,
12
12
  RemoteChain,
13
13
  UnifyAdapter
14
- } from "../chunk-IIXJVVTV.mjs";
14
+ } from "../chunk-4JBKY7XT.mjs";
15
+ import {
16
+ convertServiceAdapterError
17
+ } from "../chunk-AMUJQ6IR.mjs";
15
18
  import "../chunk-FHD4JECV.mjs";
16
19
  export {
17
20
  AnthropicAdapter,
@@ -25,6 +28,7 @@ export {
25
28
  OpenAIAdapter,
26
29
  OpenAIAssistantAdapter,
27
30
  RemoteChain,
28
- UnifyAdapter
31
+ UnifyAdapter,
32
+ convertServiceAdapterError
29
33
  };
30
34
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,9 @@
1
+ import { CopilotKitLowLevelError } from '@copilotkit/shared';
2
+
3
+ /**
4
+ * Converts service adapter errors to structured CopilotKitError format using HTTP status codes.
5
+ * This provides consistent error classification across all service adapters.
6
+ */
7
+ declare function convertServiceAdapterError(error: any, adapterName: string): CopilotKitLowLevelError;
8
+
9
+ export { convertServiceAdapterError };
@@ -0,0 +1,72 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/service-adapters/shared/index.ts
21
+ var shared_exports = {};
22
+ __export(shared_exports, {
23
+ convertServiceAdapterError: () => convertServiceAdapterError
24
+ });
25
+ module.exports = __toCommonJS(shared_exports);
26
+
27
+ // src/service-adapters/shared/error-utils.ts
28
+ var import_shared = require("@copilotkit/shared");
29
+ function convertServiceAdapterError(error, adapterName) {
30
+ var _a, _b, _c;
31
+ const errorName = ((_a = error == null ? void 0 : error.constructor) == null ? void 0 : _a.name) || error.name;
32
+ const errorMessage = (error == null ? void 0 : error.message) || String(error);
33
+ const statusCode = error.status || error.statusCode || ((_b = error.response) == null ? void 0 : _b.status);
34
+ const responseData = error.error || ((_c = error.response) == null ? void 0 : _c.data) || error.data;
35
+ const structuredError = new import_shared.CopilotKitLowLevelError({
36
+ error: error instanceof Error ? error : new Error(errorMessage),
37
+ url: `${adapterName} service adapter`,
38
+ message: `${adapterName} API error: ${errorMessage}`
39
+ });
40
+ if (statusCode) {
41
+ structuredError.statusCode = statusCode;
42
+ }
43
+ if (responseData) {
44
+ structuredError.responseData = responseData;
45
+ }
46
+ if (errorName) {
47
+ structuredError.originalErrorType = errorName;
48
+ }
49
+ let newCode;
50
+ if (statusCode === 401) {
51
+ newCode = import_shared.CopilotKitErrorCode.AUTHENTICATION_ERROR;
52
+ } else if (statusCode >= 400 && statusCode < 500) {
53
+ newCode = import_shared.CopilotKitErrorCode.CONFIGURATION_ERROR;
54
+ } else if (statusCode >= 500) {
55
+ newCode = import_shared.CopilotKitErrorCode.NETWORK_ERROR;
56
+ } else if (statusCode) {
57
+ newCode = import_shared.CopilotKitErrorCode.CONFIGURATION_ERROR;
58
+ } else {
59
+ newCode = import_shared.CopilotKitErrorCode.NETWORK_ERROR;
60
+ }
61
+ structuredError.code = newCode;
62
+ if (structuredError.extensions) {
63
+ structuredError.extensions.code = newCode;
64
+ }
65
+ return structuredError;
66
+ }
67
+ __name(convertServiceAdapterError, "convertServiceAdapterError");
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ convertServiceAdapterError
71
+ });
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/service-adapters/shared/index.ts","../../../src/service-adapters/shared/error-utils.ts"],"sourcesContent":["export * from \"./error-utils\";\n","import { CopilotKitLowLevelError, CopilotKitErrorCode } from \"@copilotkit/shared\";\n\n/**\n * Converts service adapter errors to structured CopilotKitError format using HTTP status codes.\n * This provides consistent error classification across all service adapters.\n */\nexport function convertServiceAdapterError(\n error: any,\n adapterName: string,\n): CopilotKitLowLevelError {\n const errorName = error?.constructor?.name || error.name;\n const errorMessage = error?.message || String(error);\n const statusCode = error.status || error.statusCode || error.response?.status;\n const responseData = error.error || error.response?.data || error.data;\n\n // Create the base error with the constructor signature\n const structuredError = new CopilotKitLowLevelError({\n error: error instanceof Error ? error : new Error(errorMessage),\n url: `${adapterName} service adapter`,\n message: `${adapterName} API error: ${errorMessage}`,\n });\n\n // Add additional properties after construction\n if (statusCode) {\n (structuredError as any).statusCode = statusCode;\n }\n if (responseData) {\n (structuredError as any).responseData = responseData;\n }\n if (errorName) {\n (structuredError as any).originalErrorType = errorName;\n }\n\n // Classify error based on HTTP status codes (reliable and provider-agnostic)\n let newCode: CopilotKitErrorCode;\n\n if (statusCode === 401) {\n // 401 = Authentication/API key issues\n newCode = CopilotKitErrorCode.AUTHENTICATION_ERROR;\n } else if (statusCode >= 400 && statusCode < 500) {\n // 4xx = Client errors (bad request, invalid params, etc.) - these are configuration issues\n newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;\n } else if (statusCode >= 500) {\n // 5xx = Server errors - keep as NETWORK_ERROR since it's infrastructure related\n newCode = CopilotKitErrorCode.NETWORK_ERROR;\n } else if (statusCode) {\n // Any other HTTP status with an error - likely configuration\n newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;\n } else {\n // No status code - likely a genuine network/connection error\n newCode = CopilotKitErrorCode.NETWORK_ERROR;\n }\n\n // Update both the instance property and the extensions\n (structuredError as any).code = newCode;\n if ((structuredError as any).extensions) {\n (structuredError as any).extensions.code = newCode;\n }\n\n return structuredError;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAA6D;AAMtD,SAASA,2BACdC,OACAC,aAAmB;AARrB;AAUE,QAAMC,cAAYF,oCAAOG,gBAAPH,mBAAoBI,SAAQJ,MAAMI;AACpD,QAAMC,gBAAeL,+BAAOM,YAAWC,OAAOP,KAAAA;AAC9C,QAAMQ,aAAaR,MAAMS,UAAUT,MAAMQ,gBAAcR,WAAMU,aAANV,mBAAgBS;AACvE,QAAME,eAAeX,MAAMA,WAASA,WAAMU,aAANV,mBAAgBY,SAAQZ,MAAMY;AAGlE,QAAMC,kBAAkB,IAAIC,sCAAwB;IAClDd,OAAOA,iBAAiBe,QAAQf,QAAQ,IAAIe,MAAMV,YAAAA;IAClDW,KAAK,GAAGf;IACRK,SAAS,GAAGL,0BAA0BI;EACxC,CAAA;AAGA,MAAIG,YAAY;AACbK,oBAAwBL,aAAaA;EACxC;AACA,MAAIG,cAAc;AACfE,oBAAwBF,eAAeA;EAC1C;AACA,MAAIT,WAAW;AACZW,oBAAwBI,oBAAoBf;EAC/C;AAGA,MAAIgB;AAEJ,MAAIV,eAAe,KAAK;AAEtBU,cAAUC,kCAAoBC;EAChC,WAAWZ,cAAc,OAAOA,aAAa,KAAK;AAEhDU,cAAUC,kCAAoBE;EAChC,WAAWb,cAAc,KAAK;AAE5BU,cAAUC,kCAAoBG;EAChC,WAAWd,YAAY;AAErBU,cAAUC,kCAAoBE;EAChC,OAAO;AAELH,cAAUC,kCAAoBG;EAChC;AAGCT,kBAAwBU,OAAOL;AAChC,MAAKL,gBAAwBW,YAAY;AACtCX,oBAAwBW,WAAWD,OAAOL;EAC7C;AAEA,SAAOL;AACT;AAtDgBd;","names":["convertServiceAdapterError","error","adapterName","errorName","constructor","name","errorMessage","message","String","statusCode","status","response","responseData","data","structuredError","CopilotKitLowLevelError","Error","url","originalErrorType","newCode","CopilotKitErrorCode","AUTHENTICATION_ERROR","CONFIGURATION_ERROR","NETWORK_ERROR","code","extensions"]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ convertServiceAdapterError
3
+ } from "../../chunk-AMUJQ6IR.mjs";
4
+ import "../../chunk-FHD4JECV.mjs";
5
+ export {
6
+ convertServiceAdapterError
7
+ };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +1,9 @@
1
1
  import * as graphql from 'graphql';
2
- import * as pino from 'pino';
2
+ import * as createPinoLogger from 'pino';
3
+ import createPinoLogger__default from 'pino';
3
4
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
4
5
  import { Parameter, Action, CopilotTraceHandler } from '@copilotkit/shared';
5
- import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters, f as RuntimeEventSource, g as ExtensionsResponse } from './langserve-4a5c9217.js';
6
+ import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters, f as RuntimeEventSource, g as ExtensionsResponse } from './langserve-fc5cac89.js';
6
7
  import { M as MessageInput, a as Message } from './index-d4614f9b.js';
7
8
  import { CopilotCloudOptions } from './lib/cloud/index.js';
8
9
  import { AbstractAgent } from '@ag-ui/client';
@@ -408,9 +409,9 @@ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
408
409
  declare function createLogger(options?: {
409
410
  level?: LogLevel;
410
411
  component?: string;
411
- }): pino.Logger<never>;
412
+ }): createPinoLogger__default.Logger<never>;
412
413
 
413
- declare const logger: pino.Logger<never>;
414
+ declare const logger: createPinoLogger.default.Logger<never>;
414
415
  declare const addCustomHeaderPlugin: {
415
416
  onResponse({ response }: {
416
417
  response: any;
@@ -441,6 +442,9 @@ type CommonConfig = {
441
442
  schema: ReturnType<typeof buildSchema>;
442
443
  plugins: Parameters<typeof createYoga>[0]["plugins"];
443
444
  context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
445
+ maskedErrors: {
446
+ maskError: (error: any, message: string, isDev?: boolean) => any;
447
+ };
444
448
  };
445
449
  declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
446
450
 
@@ -40,9 +40,25 @@ declare class UnknownErrorResponse extends FailedResponseStatus {
40
40
  reason: FailedResponseStatusReason;
41
41
  details: {
42
42
  description?: string;
43
+ originalError?: {
44
+ code?: string;
45
+ statusCode?: number;
46
+ severity?: string;
47
+ visibility?: string;
48
+ originalErrorType?: string;
49
+ extensions?: any;
50
+ };
43
51
  };
44
- constructor({ description }: {
52
+ constructor({ description, originalError, }: {
45
53
  description?: string;
54
+ originalError?: {
55
+ code?: string;
56
+ statusCode?: number;
57
+ severity?: string;
58
+ visibility?: string;
59
+ originalErrorType?: string;
60
+ extensions?: any;
61
+ };
46
62
  });
47
63
  }
48
64
 
@@ -157,10 +157,11 @@ var MessageStreamInterruptedResponse = class extends FailedResponseStatus {
157
157
  __name(MessageStreamInterruptedResponse, "MessageStreamInterruptedResponse");
158
158
  var UnknownErrorResponse = class extends FailedResponseStatus {
159
159
  reason = FailedResponseStatusReason.UNKNOWN_ERROR;
160
- constructor({ description }) {
160
+ constructor({ description, originalError }) {
161
161
  super();
162
162
  this.details = {
163
- description
163
+ description,
164
+ originalError
164
165
  };
165
166
  }
166
167
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts","../../src/graphql/types/response-status.type.ts","../../src/utils/failed-response-status-reasons.ts"],"sourcesContent":["export * from \"./failed-response-status-reasons\";\n","import { GraphQLJSON } from \"graphql-scalars\";\nimport { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from \"type-graphql\";\n\nexport enum ResponseStatusCode {\n Pending = \"pending\",\n Success = \"success\",\n Failed = \"failed\",\n}\n\nregisterEnumType(ResponseStatusCode, {\n name: \"ResponseStatusCode\",\n});\n\n@InterfaceType({\n resolveType(value) {\n if (value.code === ResponseStatusCode.Success) {\n return SuccessResponseStatus;\n } else if (value.code === ResponseStatusCode.Failed) {\n return FailedResponseStatus;\n } else if (value.code === ResponseStatusCode.Pending) {\n return PendingResponseStatus;\n }\n return undefined;\n },\n})\n@ObjectType()\nabstract class BaseResponseStatus {\n @Field(() => ResponseStatusCode)\n code: ResponseStatusCode;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class PendingResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Pending;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class SuccessResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Success;\n}\n\nexport enum FailedResponseStatusReason {\n GUARDRAILS_VALIDATION_FAILED = \"GUARDRAILS_VALIDATION_FAILED\",\n MESSAGE_STREAM_INTERRUPTED = \"MESSAGE_STREAM_INTERRUPTED\",\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\nregisterEnumType(FailedResponseStatusReason, {\n name: \"FailedResponseStatusReason\",\n});\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class FailedResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Failed;\n\n @Field(() => FailedResponseStatusReason)\n reason: FailedResponseStatusReason;\n\n @Field(() => GraphQLJSON, { nullable: true })\n details?: Record<string, any> = null;\n}\n\nexport const ResponseStatusUnion = createUnionType({\n name: \"ResponseStatus\",\n types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,\n});\n","import {\n FailedResponseStatus,\n FailedResponseStatusReason,\n} from \"../graphql/types/response-status.type\";\n\nexport class GuardrailsValidationFailureResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;\n declare details: {\n guardrailsReason: string;\n };\n\n constructor({ guardrailsReason }) {\n super();\n this.details = {\n guardrailsReason,\n };\n }\n}\n\nexport class MessageStreamInterruptedResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;\n declare details: {\n messageId: string;\n description: string;\n };\n\n constructor({ messageId }: { messageId: string }) {\n super();\n this.details = {\n messageId,\n description: \"Check the message for mode details\",\n };\n }\n}\n\nexport class UnknownErrorResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.UNKNOWN_ERROR;\n declare details: {\n description?: string;\n };\n\n constructor({ description }: { description?: string }) {\n super();\n this.details = {\n description,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,6BAA4B;AAC5B,0BAAoF;;;;;;;;;;;;;;;;;;UAExEA,qBAAAA;;;;GAAAA,uBAAAA,qBAAAA,CAAAA,EAAAA;IAMZC,sCAAiBD,oBAAoB;EACnCE,MAAM;AACR,CAAA;AAeA,IAAeC,qBAAf,6BAAeA,oBAAAA;EAEbC;AACF,GAHA;;MACGC,2BAAM,MAAML,kBAAAA;;GADAG,mBAAAA,WAAAA,QAAAA,MAAAA;AAAAA,qBAAAA,aAAAA;MAbdG,mCAAc;IACbC,YAAYC,OAAK;AACf,UAAIA,MAAMJ,SAAI,WAAiC;AAC7C,eAAOK;MACT,WAAWD,MAAMJ,SAAI,UAAgC;AACnD,eAAOM;MACT,WAAWF,MAAMJ,SAAI,WAAiC;AACpD,eAAOO;MACT;AACA,aAAOC;IACT;EACF,CAAA;MACCC,gCAAAA;GACcV,kBAAAA;AAMR,IAAMQ,wBAAN,cAAoCR,mBAAAA;EACzCC,OAAAA;AACF;AAFaO;AAAAA,wBAAAA,aAAAA;MADZE,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCQ,qBAAAA;AAKN,IAAMF,wBAAN,cAAoCN,mBAAAA;EACzCC,OAAAA;AACF;AAFaK;AAAAA,wBAAAA,aAAAA;MADZI,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCM,qBAAAA;;UAIDM,6BAAAA;;;;GAAAA,+BAAAA,6BAAAA,CAAAA,EAAAA;IAMZd,sCAAiBc,4BAA4B;EAC3Cb,MAAM;AACR,CAAA;AAGO,IAAMQ,uBAAN,cAAmCP,mBAAAA;EACxCC,OAAAA;EAGAY;EAGAC,UAAgC;AAClC;AARaP;;MAGVL,2BAAM,MAAMU,0BAAAA;;GAHFL,qBAAAA,WAAAA,UAAAA,MAAAA;;MAMVL,2BAAM,MAAMa,oCAAa;IAAEC,UAAU;EAAK,CAAA;qCACjC,WAAA,cAAA,SAAA,MAAA;GAPCT,qBAAAA,WAAAA,WAAAA,MAAAA;AAAAA,uBAAAA,aAAAA;MADZG,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCO,oBAAAA;AAUN,IAAMU,0BAAsBC,qCAAgB;EACjDnB,MAAM;EACNoB,OAAO,MAAM;IAACX;IAAuBF;IAAuBC;;AAC9D,CAAA;;;AC5DO,IAAMa,sCAAN,cAAkDC,qBAAAA;EACvDC,SAASC,2BAA2BC;EAKpCC,YAAY,EAAEC,iBAAgB,GAAI;AAChC,UAAK;AACL,SAAKC,UAAU;MACbD;IACF;EACF;AACF;AAZaN;AAcN,IAAMQ,mCAAN,cAA+CP,qBAAAA;EACpDC,SAASC,2BAA2BM;EAMpCJ,YAAY,EAAEK,UAAS,GAA2B;AAChD,UAAK;AACL,SAAKH,UAAU;MACbG;MACAC,aAAa;IACf;EACF;AACF;AAdaH;AAgBN,IAAMI,uBAAN,cAAmCX,qBAAAA;EACxCC,SAASC,2BAA2BU;EAKpCR,YAAY,EAAEM,YAAW,GAA8B;AACrD,UAAK;AACL,SAAKJ,UAAU;MACbI;IACF;EACF;AACF;AAZaC;","names":["ResponseStatusCode","registerEnumType","name","BaseResponseStatus","code","Field","InterfaceType","resolveType","value","SuccessResponseStatus","FailedResponseStatus","PendingResponseStatus","undefined","ObjectType","implements","FailedResponseStatusReason","reason","details","GraphQLJSON","nullable","ResponseStatusUnion","createUnionType","types","GuardrailsValidationFailureResponse","FailedResponseStatus","reason","FailedResponseStatusReason","GUARDRAILS_VALIDATION_FAILED","constructor","guardrailsReason","details","MessageStreamInterruptedResponse","MESSAGE_STREAM_INTERRUPTED","messageId","description","UnknownErrorResponse","UNKNOWN_ERROR"]}
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/graphql/types/response-status.type.ts","../../src/utils/failed-response-status-reasons.ts"],"sourcesContent":["export * from \"./failed-response-status-reasons\";\n","import { GraphQLJSON } from \"graphql-scalars\";\nimport { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from \"type-graphql\";\n\nexport enum ResponseStatusCode {\n Pending = \"pending\",\n Success = \"success\",\n Failed = \"failed\",\n}\n\nregisterEnumType(ResponseStatusCode, {\n name: \"ResponseStatusCode\",\n});\n\n@InterfaceType({\n resolveType(value) {\n if (value.code === ResponseStatusCode.Success) {\n return SuccessResponseStatus;\n } else if (value.code === ResponseStatusCode.Failed) {\n return FailedResponseStatus;\n } else if (value.code === ResponseStatusCode.Pending) {\n return PendingResponseStatus;\n }\n return undefined;\n },\n})\n@ObjectType()\nabstract class BaseResponseStatus {\n @Field(() => ResponseStatusCode)\n code: ResponseStatusCode;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class PendingResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Pending;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class SuccessResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Success;\n}\n\nexport enum FailedResponseStatusReason {\n GUARDRAILS_VALIDATION_FAILED = \"GUARDRAILS_VALIDATION_FAILED\",\n MESSAGE_STREAM_INTERRUPTED = \"MESSAGE_STREAM_INTERRUPTED\",\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\nregisterEnumType(FailedResponseStatusReason, {\n name: \"FailedResponseStatusReason\",\n});\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class FailedResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Failed;\n\n @Field(() => FailedResponseStatusReason)\n reason: FailedResponseStatusReason;\n\n @Field(() => GraphQLJSON, { nullable: true })\n details?: Record<string, any> = null;\n}\n\nexport const ResponseStatusUnion = createUnionType({\n name: \"ResponseStatus\",\n types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,\n});\n","import {\n FailedResponseStatus,\n FailedResponseStatusReason,\n} from \"../graphql/types/response-status.type\";\n\nexport class GuardrailsValidationFailureResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;\n declare details: {\n guardrailsReason: string;\n };\n\n constructor({ guardrailsReason }) {\n super();\n this.details = {\n guardrailsReason,\n };\n }\n}\n\nexport class MessageStreamInterruptedResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;\n declare details: {\n messageId: string;\n description: string;\n };\n\n constructor({ messageId }: { messageId: string }) {\n super();\n this.details = {\n messageId,\n description: \"Check the message for mode details\",\n };\n }\n}\n\nexport class UnknownErrorResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.UNKNOWN_ERROR;\n declare details: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n };\n\n constructor({\n description,\n originalError,\n }: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n }) {\n super();\n this.details = {\n description,\n originalError,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,6BAA4B;AAC5B,0BAAoF;;;;;;;;;;;;;;;;;;UAExEA,qBAAAA;;;;GAAAA,uBAAAA,qBAAAA,CAAAA,EAAAA;IAMZC,sCAAiBD,oBAAoB;EACnCE,MAAM;AACR,CAAA;AAeA,IAAeC,qBAAf,6BAAeA,oBAAAA;EAEbC;AACF,GAHA;;MACGC,2BAAM,MAAML,kBAAAA;;GADAG,mBAAAA,WAAAA,QAAAA,MAAAA;AAAAA,qBAAAA,aAAAA;MAbdG,mCAAc;IACbC,YAAYC,OAAK;AACf,UAAIA,MAAMJ,SAAI,WAAiC;AAC7C,eAAOK;MACT,WAAWD,MAAMJ,SAAI,UAAgC;AACnD,eAAOM;MACT,WAAWF,MAAMJ,SAAI,WAAiC;AACpD,eAAOO;MACT;AACA,aAAOC;IACT;EACF,CAAA;MACCC,gCAAAA;GACcV,kBAAAA;AAMR,IAAMQ,wBAAN,cAAoCR,mBAAAA;EACzCC,OAAAA;AACF;AAFaO;AAAAA,wBAAAA,aAAAA;MADZE,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCQ,qBAAAA;AAKN,IAAMF,wBAAN,cAAoCN,mBAAAA;EACzCC,OAAAA;AACF;AAFaK;AAAAA,wBAAAA,aAAAA;MADZI,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCM,qBAAAA;;UAIDM,6BAAAA;;;;GAAAA,+BAAAA,6BAAAA,CAAAA,EAAAA;IAMZd,sCAAiBc,4BAA4B;EAC3Cb,MAAM;AACR,CAAA;AAGO,IAAMQ,uBAAN,cAAmCP,mBAAAA;EACxCC,OAAAA;EAGAY;EAGAC,UAAgC;AAClC;AARaP;;MAGVL,2BAAM,MAAMU,0BAAAA;;GAHFL,qBAAAA,WAAAA,UAAAA,MAAAA;;MAMVL,2BAAM,MAAMa,oCAAa;IAAEC,UAAU;EAAK,CAAA;qCACjC,WAAA,cAAA,SAAA,MAAA;GAPCT,qBAAAA,WAAAA,WAAAA,MAAAA;AAAAA,uBAAAA,aAAAA;MADZG,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCO,oBAAAA;AAUN,IAAMU,0BAAsBC,qCAAgB;EACjDnB,MAAM;EACNoB,OAAO,MAAM;IAACX;IAAuBF;IAAuBC;;AAC9D,CAAA;;;AC5DO,IAAMa,sCAAN,cAAkDC,qBAAAA;EACvDC,SAASC,2BAA2BC;EAKpCC,YAAY,EAAEC,iBAAgB,GAAI;AAChC,UAAK;AACL,SAAKC,UAAU;MACbD;IACF;EACF;AACF;AAZaN;AAcN,IAAMQ,mCAAN,cAA+CP,qBAAAA;EACpDC,SAASC,2BAA2BM;EAMpCJ,YAAY,EAAEK,UAAS,GAA2B;AAChD,UAAK;AACL,SAAKH,UAAU;MACbG;MACAC,aAAa;IACf;EACF;AACF;AAdaH;AAgBN,IAAMI,uBAAN,cAAmCX,qBAAAA;EACxCC,SAASC,2BAA2BU;EAapCR,YAAY,EACVM,aACAG,cAAa,GAWZ;AACD,UAAK;AACL,SAAKP,UAAU;MACbI;MACAG;IACF;EACF;AACF;AAlCaF;","names":["ResponseStatusCode","registerEnumType","name","BaseResponseStatus","code","Field","InterfaceType","resolveType","value","SuccessResponseStatus","FailedResponseStatus","PendingResponseStatus","undefined","ObjectType","implements","FailedResponseStatusReason","reason","details","GraphQLJSON","nullable","ResponseStatusUnion","createUnionType","types","GuardrailsValidationFailureResponse","FailedResponseStatus","reason","FailedResponseStatusReason","GUARDRAILS_VALIDATION_FAILED","constructor","guardrailsReason","details","MessageStreamInterruptedResponse","MESSAGE_STREAM_INTERRUPTED","messageId","description","UnknownErrorResponse","UNKNOWN_ERROR","originalError"]}
@@ -2,7 +2,7 @@ import {
2
2
  GuardrailsValidationFailureResponse,
3
3
  MessageStreamInterruptedResponse,
4
4
  UnknownErrorResponse
5
- } from "../chunk-5BIEM2UU.mjs";
5
+ } from "../chunk-XWBDEXDA.mjs";
6
6
  import "../chunk-FHD4JECV.mjs";
7
7
  export {
8
8
  GuardrailsValidationFailureResponse,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.9.2-next.7",
12
+ "version": "1.9.2-next.9",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -66,7 +66,7 @@
66
66
  "rxjs": "7.8.1",
67
67
  "type-graphql": "2.0.0-rc.1",
68
68
  "zod": "^3.23.3",
69
- "@copilotkit/shared": "1.9.2-next.7"
69
+ "@copilotkit/shared": "1.9.2-next.9"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@ag-ui/client": ">=0.0.28",
@@ -1,11 +1,12 @@
1
+ import { CopilotKitLowLevelError, isStructuredCopilotKitError } from "@copilotkit/shared";
1
2
  import { catchError, mergeMap, ReplaySubject, scan } from "rxjs";
2
- import { CustomEventNames, LangGraphEvent, LangGraphEventTypes } from "./events";
3
+ import { generateHelpfulErrorMessage } from "../../lib/streaming";
3
4
  import {
4
5
  RuntimeEvent,
5
6
  RuntimeEventTypes,
6
7
  RuntimeMetaEventName,
7
8
  } from "../../service-adapters/events";
8
- import { randomId, CopilotKitError } from "@copilotkit/shared";
9
+ import { CustomEventNames, LangGraphEvent, LangGraphEventTypes } from "./events";
9
10
 
10
11
  interface LangGraphEventWithState {
11
12
  event: LangGraphEvent | null;
@@ -155,6 +156,31 @@ export class RemoteLangGraphEventSource {
155
156
  });
156
157
  }
157
158
 
159
+ // Handle CopilotKit error events with preserved semantic information
160
+ if (acc.event.event === LangGraphEventTypes.OnCopilotKitError) {
161
+ const errorData = acc.event.data.error;
162
+
163
+ // Create a structured error with the original semantic information
164
+ const preservedError = new CopilotKitLowLevelError({
165
+ error: new Error(errorData.message),
166
+ url: "langgraph agent",
167
+ message: `${errorData.type}: ${errorData.message}`,
168
+ });
169
+
170
+ // Add additional error context to the error object
171
+ if (errorData.status_code) {
172
+ (preservedError as any).statusCode = errorData.status_code;
173
+ }
174
+ if (errorData.response_data) {
175
+ (preservedError as any).responseData = errorData.response_data;
176
+ }
177
+ (preservedError as any).agentName = errorData.agent_name;
178
+ (preservedError as any).originalErrorType = errorData.type;
179
+
180
+ // Throw the structured error to be handled by the catchError operator
181
+ throw preservedError;
182
+ }
183
+
158
184
  const responseMetadata = this.getResponseMetadata(acc.event);
159
185
 
160
186
  // Tool call ended: emit ActionExecutionEnd
@@ -283,48 +309,20 @@ export class RemoteLangGraphEventSource {
283
309
  return events;
284
310
  }),
285
311
  catchError((error) => {
286
- console.error(error);
287
-
288
312
  // If it's a structured CopilotKitError, re-throw it to be handled by the frontend error system
289
- if (
290
- error instanceof CopilotKitError ||
291
- (error?.name && error.name.includes("CopilotKit"))
292
- ) {
313
+ if (isStructuredCopilotKitError(error)) {
293
314
  throw error;
294
315
  }
295
316
 
296
- const events: RuntimeEvent[] = [];
297
-
298
- if (lastEventWithState?.lastMessageId && !lastEventWithState.isToolCall) {
299
- events.push({
300
- type: RuntimeEventTypes.TextMessageEnd,
301
- messageId: lastEventWithState.lastMessageId,
302
- });
303
- }
304
- if (lastEventWithState?.lastToolCallId) {
305
- events.push({
306
- type: RuntimeEventTypes.ActionExecutionEnd,
307
- actionExecutionId: lastEventWithState.lastToolCallId,
308
- });
309
- }
310
-
311
- const messageId = randomId();
317
+ // Determine a more helpful error message based on context
318
+ let helpfulMessage = generateHelpfulErrorMessage(error, "LangGraph agent connection");
312
319
 
313
- events.push({
314
- type: RuntimeEventTypes.TextMessageStart,
315
- messageId: messageId,
316
- });
317
- events.push({
318
- type: RuntimeEventTypes.TextMessageContent,
319
- messageId: messageId,
320
- content: "❌ An error occurred. Please try again.",
320
+ // For all other errors, preserve the raw error information in a structured format
321
+ throw new CopilotKitLowLevelError({
322
+ error: error instanceof Error ? error : new Error(String(error)),
323
+ url: "langgraph event stream",
324
+ message: helpfulMessage,
321
325
  });
322
- events.push({
323
- type: RuntimeEventTypes.TextMessageEnd,
324
- messageId: messageId,
325
- });
326
-
327
- return events;
328
326
  }),
329
327
  );
330
328
  }
@@ -15,6 +15,7 @@ export enum LangGraphEventTypes {
15
15
  OnCustomEvent = "on_custom_event",
16
16
  OnInterrupt = "on_interrupt",
17
17
  OnCopilotKitInterrupt = "on_copilotkit_interrupt",
18
+ OnCopilotKitError = "on_copilotkit_error",
18
19
  }
19
20
 
20
21
  export enum MetaEventNames {
@@ -344,6 +345,22 @@ interface CopilotKitLangGraphInterruptEvent {
344
345
  data: { value: string; messages: (TextMessage | ActionExecutionMessage | ResultMessage)[] };
345
346
  }
346
347
 
348
+ interface CopilotKitLangGraphErrorEvent {
349
+ event: LangGraphEventTypes.OnCopilotKitError;
350
+ data: {
351
+ error: {
352
+ message: string;
353
+ type: string;
354
+ agent_name: string;
355
+ status_code?: number;
356
+ response_data?: any;
357
+ };
358
+ thread_id: string;
359
+ agent_name: string;
360
+ node_name: string;
361
+ };
362
+ }
363
+
347
364
  export type LangGraphEvent =
348
365
  | LangGraphOnChainStartEvent
349
366
  | LangGraphOnChainStreamEvent
@@ -356,4 +373,5 @@ export type LangGraphEvent =
356
373
  | LangGraphOnCopilotKitStateSyncEvent
357
374
  | LangGraphOnCustomEvent
358
375
  | LangGraphInterruptEvent
359
- | CopilotKitLangGraphInterruptEvent;
376
+ | CopilotKitLangGraphInterruptEvent
377
+ | CopilotKitLangGraphErrorEvent;
@@ -54,7 +54,11 @@ import telemetry from "../../lib/telemetry-client";
54
54
  import { randomId } from "@copilotkit/shared";
55
55
  import { AgentsResponse } from "../types/agents-response.type";
56
56
  import { LangGraphEventTypes } from "../../agents/langgraph/events";
57
- import { CopilotKitError } from "@copilotkit/shared";
57
+ import {
58
+ CopilotKitError,
59
+ CopilotKitLowLevelError,
60
+ isStructuredCopilotKitError,
61
+ } from "@copilotkit/shared";
58
62
 
59
63
  const invokeGuardrails = async ({
60
64
  baseUrl,
@@ -235,6 +239,40 @@ export class CopilotResolver {
235
239
  }
236
240
 
237
241
  logger.debug("Processing");
242
+ let runtimeResponse;
243
+ try {
244
+ runtimeResponse = await copilotRuntime.processRuntimeRequest({
245
+ serviceAdapter,
246
+ messages: data.messages,
247
+ actions: data.frontend.actions.filter(
248
+ (action) => action.available !== ActionInputAvailability.disabled,
249
+ ),
250
+ threadId: data.threadId,
251
+ runId: data.runId,
252
+ publicApiKey: copilotCloudPublicApiKey,
253
+ outputMessagesPromise,
254
+ graphqlContext: ctx,
255
+ forwardedParameters: data.forwardedParameters,
256
+ agentSession: data.agentSession,
257
+ agentStates: data.agentStates,
258
+ url: data.frontend.url,
259
+ extensions: data.extensions,
260
+ metaEvents: data.metaEvents,
261
+ });
262
+ } catch (error) {
263
+ // Catch structured CopilotKit errors at the main mutation level and re-throw as GraphQL errors
264
+ if (isStructuredCopilotKitError(error) || (error as any)?.extensions?.visibility) {
265
+ throw new GraphQLError(error.message || "Agent error occurred", {
266
+ extensions: {
267
+ ...(error as any).extensions,
268
+ code: (error as any).code || (error as any).extensions?.code || "AGENT_ERROR",
269
+ originalError: error,
270
+ },
271
+ });
272
+ }
273
+ throw error; // Re-throw non-CopilotKit errors as-is
274
+ }
275
+
238
276
  const {
239
277
  eventSource,
240
278
  threadId = randomId(),
@@ -242,24 +280,7 @@ export class CopilotResolver {
242
280
  serverSideActions,
243
281
  actionInputsWithoutAgents,
244
282
  extensions,
245
- } = await copilotRuntime.processRuntimeRequest({
246
- serviceAdapter,
247
- messages: data.messages,
248
- actions: data.frontend.actions.filter(
249
- (action) => action.available !== ActionInputAvailability.disabled,
250
- ),
251
- threadId: data.threadId,
252
- runId: data.runId,
253
- publicApiKey: copilotCloudPublicApiKey,
254
- outputMessagesPromise,
255
- graphqlContext: ctx,
256
- forwardedParameters: data.forwardedParameters,
257
- agentSession: data.agentSession,
258
- agentStates: data.agentStates,
259
- url: data.frontend.url,
260
- extensions: data.extensions,
261
- metaEvents: data.metaEvents,
262
- });
283
+ } = runtimeResponse;
263
284
 
264
285
  logger.debug("Event source created, creating response");
265
286
  // run and process the event stream
@@ -357,12 +378,21 @@ export class CopilotResolver {
357
378
  }
358
379
  },
359
380
  error: (err) => {
360
- logger.error({ err }, "Error in meta events stream");
361
- responseStatus$.next(
362
- new UnknownErrorResponse({
363
- description: `An unknown error has occurred in the event stream`,
364
- }),
365
- );
381
+ // For structured CopilotKit errors, set proper error response status
382
+ if (err?.name?.includes("CopilotKit") || err?.extensions?.visibility) {
383
+ responseStatus$.next(
384
+ new UnknownErrorResponse({
385
+ description: err.message || "Agent error occurred",
386
+ }),
387
+ );
388
+ } else {
389
+ responseStatus$.next(
390
+ new UnknownErrorResponse({
391
+ description: `An unknown error has occurred in the event stream`,
392
+ }),
393
+ );
394
+ }
395
+
366
396
  eventStreamSubscription?.unsubscribe();
367
397
  stop();
368
398
  },
@@ -444,20 +474,20 @@ export class CopilotResolver {
444
474
  // create a sub stream that contains the message content
445
475
  const textMessageContentStream = eventStream.pipe(
446
476
  // skip until this message start event
447
- skipWhile((e) => e !== event),
477
+ skipWhile((e: RuntimeEvent) => e !== event),
448
478
  // take until the message end event
449
479
  takeWhile(
450
- (e) =>
480
+ (e: RuntimeEvent) =>
451
481
  !(
452
482
  e.type === RuntimeEventTypes.TextMessageEnd &&
453
- e.messageId == event.messageId
483
+ (e as any).messageId == event.messageId
454
484
  ),
455
485
  ),
456
486
  // filter out any other message events or message ids
457
487
  filter(
458
- (e) =>
488
+ (e: RuntimeEvent) =>
459
489
  e.type == RuntimeEventTypes.TextMessageContent &&
460
- e.messageId == event.messageId,
490
+ (e as any).messageId == event.messageId,
461
491
  ),
462
492
  );
463
493
 
@@ -539,20 +569,20 @@ export class CopilotResolver {
539
569
  case RuntimeEventTypes.ActionExecutionStart:
540
570
  logger.debug("Action execution start event received");
541
571
  const actionExecutionArgumentStream = eventStream.pipe(
542
- skipWhile((e) => e !== event),
572
+ skipWhile((e: RuntimeEvent) => e !== event),
543
573
  // take until the action execution end event
544
574
  takeWhile(
545
- (e) =>
575
+ (e: RuntimeEvent) =>
546
576
  !(
547
577
  e.type === RuntimeEventTypes.ActionExecutionEnd &&
548
- e.actionExecutionId == event.actionExecutionId
578
+ (e as any).actionExecutionId == event.actionExecutionId
549
579
  ),
550
580
  ),
551
581
  // filter out any other action execution events or action execution ids
552
582
  filter(
553
- (e) =>
583
+ (e: RuntimeEvent) =>
554
584
  e.type == RuntimeEventTypes.ActionExecutionArgs &&
555
- e.actionExecutionId == event.actionExecutionId,
585
+ (e as any).actionExecutionId == event.actionExecutionId,
556
586
  ),
557
587
  );
558
588
  const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
@@ -665,16 +695,30 @@ export class CopilotResolver {
665
695
  }
666
696
  },
667
697
  error: (err) => {
668
- logger.error({ err }, "Error in event stream");
669
-
670
- // If it's a structured CopilotKitError, stop the repeater with the error so frontend can handle it
698
+ // For structured CopilotKit errors, set proper error response status
671
699
  if (
672
700
  err instanceof CopilotKitError ||
673
- (err instanceof Error && err.name && err.name.includes("CopilotKit"))
701
+ err instanceof CopilotKitLowLevelError ||
702
+ (err instanceof Error && err.name && err.name.includes("CopilotKit")) ||
703
+ err?.extensions?.visibility
674
704
  ) {
705
+ responseStatus$.next(
706
+ new UnknownErrorResponse({
707
+ description: err.message || "Agent error occurred",
708
+ // Include original error information for frontend to extract
709
+ originalError: {
710
+ code: err.code || err.extensions?.code,
711
+ statusCode: err.statusCode || err.extensions?.statusCode,
712
+ severity: err.severity || err.extensions?.severity,
713
+ visibility: err.visibility || err.extensions?.visibility,
714
+ originalErrorType: err.originalErrorType || err.extensions?.originalErrorType,
715
+ extensions: err.extensions,
716
+ },
717
+ }),
718
+ );
675
719
  eventStreamSubscription?.unsubscribe();
676
720
  rejectOutputMessagesPromise(err);
677
- stopStreamingMessages(err); // Pass the error to stop the GraphQL stream with this error
721
+ stopStreamingMessages();
678
722
  return;
679
723
  }
680
724