@copilotkit/runtime 1.9.2-next.2 → 1.9.2-next.20
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 +130 -0
- package/dist/{chunk-6TQCQ3WJ.mjs → chunk-6KWGISZM.mjs} +2 -2
- package/dist/chunk-AMUJQ6IR.mjs +50 -0
- package/dist/chunk-AMUJQ6IR.mjs.map +1 -0
- package/dist/{chunk-CD2SZGIZ.mjs → chunk-GJ2JWK4N.mjs} +2 -2
- package/dist/{chunk-DOWRU5U6.mjs → chunk-IKR6ULGF.mjs} +2353 -1854
- package/dist/chunk-IKR6ULGF.mjs.map +1 -0
- package/dist/{chunk-IIXJVVTV.mjs → chunk-QLLV2QVK.mjs} +132 -78
- package/dist/chunk-QLLV2QVK.mjs.map +1 -0
- package/dist/{chunk-D3SPXEVJ.mjs → chunk-S77YPKO6.mjs} +2 -2
- package/dist/{chunk-5BIEM2UU.mjs → chunk-XWBDEXDA.mjs} +4 -3
- package/dist/{chunk-5BIEM2UU.mjs.map → chunk-XWBDEXDA.mjs.map} +1 -1
- package/dist/{chunk-ODF35LFG.mjs → chunk-ZJZTEQVW.mjs} +19 -2
- package/dist/chunk-ZJZTEQVW.mjs.map +1 -0
- package/dist/{groq-adapter-25a2bd35.d.ts → groq-adapter-098f97f6.d.ts} +5 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3728 -3114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -8
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +5 -4
- package/dist/lib/index.js +2711 -2140
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -8
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +160 -96
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +7 -6
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +160 -96
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +5 -4
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +160 -96
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +5 -4
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +160 -96
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +4 -3
- package/dist/service-adapters/index.d.ts +6 -4
- package/dist/service-adapters/index.js +202 -107
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +6 -2
- package/dist/service-adapters/shared/index.d.ts +9 -0
- package/dist/service-adapters/shared/index.js +72 -0
- package/dist/service-adapters/shared/index.js.map +1 -0
- package/dist/service-adapters/shared/index.mjs +8 -0
- package/dist/service-adapters/shared/index.mjs.map +1 -0
- package/dist/{shared-e272b15a.d.ts → shared-41d4988d.d.ts} +45 -5
- package/dist/utils/index.d.ts +17 -1
- package/dist/utils/index.js +3 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +36 -38
- package/src/agents/langgraph/events.ts +19 -1
- package/src/graphql/resolvers/copilot.resolver.ts +107 -45
- package/src/graphql/resolvers/state.resolver.ts +3 -3
- package/src/lib/error-messages.ts +200 -0
- package/src/lib/integrations/shared.ts +43 -0
- package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +169 -0
- package/src/lib/runtime/agui-action.ts +9 -3
- package/src/lib/runtime/copilot-runtime.ts +384 -83
- package/src/lib/runtime/langgraph/langgraph-agent.ts +12 -0
- package/src/lib/runtime/remote-action-constructors.ts +28 -3
- package/src/lib/runtime/remote-actions.ts +6 -0
- package/src/lib/runtime/remote-lg-action.ts +130 -40
- package/src/lib/streaming.ts +125 -36
- package/src/service-adapters/anthropic/anthropic-adapter.ts +67 -8
- package/src/service-adapters/anthropic/utils.ts +3 -8
- package/src/service-adapters/events.ts +37 -81
- package/src/service-adapters/google/google-genai-adapter.ts +5 -0
- package/src/service-adapters/groq/groq-adapter.ts +66 -56
- package/src/service-adapters/index.ts +1 -0
- package/src/service-adapters/openai/openai-adapter.ts +4 -3
- package/src/service-adapters/shared/error-utils.ts +61 -0
- package/src/service-adapters/shared/index.ts +1 -0
- package/src/utils/failed-response-status-reasons.ts +23 -1
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +172 -387
- package/dist/chunk-DOWRU5U6.mjs.map +0 -1
- package/dist/chunk-IIXJVVTV.mjs.map +0 -1
- package/dist/chunk-ODF35LFG.mjs.map +0 -1
- package/dist/{chunk-6TQCQ3WJ.mjs.map → chunk-6KWGISZM.mjs.map} +0 -0
- package/dist/{chunk-CD2SZGIZ.mjs.map → chunk-GJ2JWK4N.mjs.map} +0 -0
- package/dist/{chunk-D3SPXEVJ.mjs.map → chunk-S77YPKO6.mjs.map} +0 -0
- 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-
|
|
14
|
+
} from "../chunk-QLLV2QVK.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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as graphql from 'graphql';
|
|
2
|
-
import * as
|
|
2
|
+
import * as createPinoLogger from 'pino';
|
|
3
|
+
import createPinoLogger__default from 'pino';
|
|
3
4
|
import { YogaInitialContext, createYoga } from 'graphql-yoga';
|
|
4
|
-
import { Parameter, Action } 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-
|
|
5
|
+
import { Parameter, Action, CopilotErrorHandler } from '@copilotkit/shared';
|
|
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';
|
|
@@ -338,6 +339,24 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
|
|
|
338
339
|
* ```
|
|
339
340
|
*/
|
|
340
341
|
createMCPClient?: CreateMCPClientFunction;
|
|
342
|
+
/**
|
|
343
|
+
* Optional error handler for comprehensive debugging and observability.
|
|
344
|
+
*
|
|
345
|
+
* **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
|
|
346
|
+
* This is a premium CopilotKit Cloud feature.
|
|
347
|
+
*
|
|
348
|
+
* @param errorEvent - Structured error event with rich debugging context
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* const runtime = new CopilotRuntime({
|
|
353
|
+
* onError: (errorEvent) => {
|
|
354
|
+
* debugDashboard.capture(errorEvent);
|
|
355
|
+
* }
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
onError?: CopilotErrorHandler;
|
|
341
360
|
}
|
|
342
361
|
declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
343
362
|
actions: ActionsConfiguration<T>;
|
|
@@ -349,18 +368,36 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
349
368
|
private delegateAgentProcessingToServiceAdapter;
|
|
350
369
|
private observability?;
|
|
351
370
|
private availableAgents;
|
|
371
|
+
private onError?;
|
|
372
|
+
private hasWarnedAboutError;
|
|
352
373
|
private readonly mcpServersConfig?;
|
|
353
374
|
private mcpActionCache;
|
|
354
375
|
private readonly createMCPClientImpl?;
|
|
355
376
|
constructor(params?: CopilotRuntimeConstructorParams<T>);
|
|
356
377
|
private injectMCPToolInstructions;
|
|
357
378
|
processRuntimeRequest(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
|
|
379
|
+
getAllAgents(graphqlContext: GraphQLContext): Promise<(AgentWithEndpoint | Agent)[]>;
|
|
358
380
|
discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]>;
|
|
381
|
+
discoverAgentsFromAgui(): Agent[];
|
|
359
382
|
loadAgentState(graphqlContext: GraphQLContext, threadId: string, agentName: string): Promise<LoadAgentStateResponse>;
|
|
360
383
|
private processAgentRequest;
|
|
361
384
|
private getServerSideActions;
|
|
362
385
|
private detectProvider;
|
|
363
386
|
private convertStreamingErrorToStructured;
|
|
387
|
+
private error;
|
|
388
|
+
/**
|
|
389
|
+
* Public method to handle GraphQL validation errors
|
|
390
|
+
* This allows the GraphQL resolver to send validation errors through the error system
|
|
391
|
+
*/
|
|
392
|
+
errorGraphQLError(error: {
|
|
393
|
+
message: string;
|
|
394
|
+
code: string;
|
|
395
|
+
type: string;
|
|
396
|
+
}, context: {
|
|
397
|
+
operation: string;
|
|
398
|
+
cloudConfigPresent: boolean;
|
|
399
|
+
guardrailsEnabled: boolean;
|
|
400
|
+
}): Promise<void>;
|
|
364
401
|
}
|
|
365
402
|
declare function flattenToolCallsNoDuplicates(toolsByPriority: ActionInput[]): ActionInput[];
|
|
366
403
|
declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): CopilotKitEndpoint;
|
|
@@ -372,9 +409,9 @@ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
|
|
|
372
409
|
declare function createLogger(options?: {
|
|
373
410
|
level?: LogLevel;
|
|
374
411
|
component?: string;
|
|
375
|
-
}):
|
|
412
|
+
}): createPinoLogger__default.Logger<never>;
|
|
376
413
|
|
|
377
|
-
declare const logger:
|
|
414
|
+
declare const logger: createPinoLogger.default.Logger<never>;
|
|
378
415
|
declare const addCustomHeaderPlugin: {
|
|
379
416
|
onResponse({ response }: {
|
|
380
417
|
response: any;
|
|
@@ -405,6 +442,9 @@ type CommonConfig = {
|
|
|
405
442
|
schema: ReturnType<typeof buildSchema>;
|
|
406
443
|
plugins: Parameters<typeof createYoga>[0]["plugins"];
|
|
407
444
|
context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
|
|
445
|
+
maskedErrors: {
|
|
446
|
+
maskError: (error: any, message: string, isDev?: boolean) => any;
|
|
447
|
+
};
|
|
408
448
|
};
|
|
409
449
|
declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
|
|
410
450
|
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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
|
|
package/dist/utils/index.js
CHANGED
|
@@ -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
|
};
|
package/dist/utils/index.js.map
CHANGED
|
@@ -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({
|
|
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"]}
|
package/dist/utils/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.9.2-next.
|
|
12
|
+
"version": "1.9.2-next.20",
|
|
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.
|
|
69
|
+
"@copilotkit/shared": "1.9.2-next.20"
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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;
|