@copilotkit/runtime 1.9.2-next.10 → 1.9.2-next.2
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 +0 -59
- package/dist/{chunk-XWBDEXDA.mjs → chunk-5BIEM2UU.mjs} +3 -4
- package/dist/{chunk-XWBDEXDA.mjs.map → chunk-5BIEM2UU.mjs.map} +1 -1
- package/dist/{chunk-TOBFVWZU.mjs → chunk-6TQCQ3WJ.mjs} +2 -2
- package/dist/{chunk-VBXBFZEL.mjs → chunk-CD2SZGIZ.mjs} +2 -2
- package/dist/{chunk-6RUTA76W.mjs → chunk-D3SPXEVJ.mjs} +2 -2
- package/dist/{chunk-PMIAGZGS.mjs → chunk-DOWRU5U6.mjs} +2414 -2928
- package/dist/chunk-DOWRU5U6.mjs.map +1 -0
- package/dist/{chunk-GS7DO47Q.mjs → chunk-IIXJVVTV.mjs} +78 -155
- package/dist/chunk-IIXJVVTV.mjs.map +1 -0
- package/dist/{chunk-5OK4GLKL.mjs → chunk-ODF35LFG.mjs} +2 -19
- package/dist/chunk-ODF35LFG.mjs.map +1 -0
- package/dist/{groq-adapter-172a2ca4.d.ts → groq-adapter-25a2bd35.d.ts} +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2598 -3250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -12
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +4 -5
- package/dist/lib/index.js +2730 -3339
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -9
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +96 -160
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -7
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +96 -160
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -5
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +96 -160
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -5
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +96 -160
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -4
- package/dist/service-adapters/index.d.ts +4 -6
- package/dist/service-adapters/index.js +107 -225
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +2 -6
- package/dist/{shared-bd953ebf.d.ts → shared-e272b15a.d.ts} +5 -45
- package/dist/utils/index.d.ts +1 -17
- package/dist/utils/index.js +2 -3
- 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 +38 -36
- package/src/agents/langgraph/events.ts +1 -19
- package/src/graphql/resolvers/copilot.resolver.ts +45 -108
- package/src/graphql/resolvers/state.resolver.ts +3 -3
- package/src/lib/integrations/shared.ts +0 -43
- package/src/lib/runtime/copilot-runtime.ts +83 -412
- package/src/lib/runtime/langgraph/langgraph-agent.ts +0 -12
- package/src/lib/runtime/remote-action-constructors.ts +3 -28
- package/src/lib/runtime/remote-lg-action.ts +40 -130
- package/src/lib/streaming.ts +36 -125
- package/src/service-adapters/anthropic/anthropic-adapter.ts +8 -67
- package/src/service-adapters/anthropic/utils.ts +8 -3
- package/src/service-adapters/events.ts +81 -37
- package/src/service-adapters/groq/groq-adapter.ts +56 -66
- package/src/service-adapters/index.ts +0 -1
- package/src/service-adapters/openai/openai-adapter.ts +3 -18
- package/src/utils/failed-response-status-reasons.ts +1 -23
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +387 -172
- package/dist/chunk-5OK4GLKL.mjs.map +0 -1
- package/dist/chunk-AMUJQ6IR.mjs +0 -50
- package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
- package/dist/chunk-GS7DO47Q.mjs.map +0 -1
- package/dist/chunk-PMIAGZGS.mjs.map +0 -1
- package/dist/service-adapters/shared/index.d.ts +0 -9
- package/dist/service-adapters/shared/index.js +0 -72
- package/dist/service-adapters/shared/index.js.map +0 -1
- package/dist/service-adapters/shared/index.mjs +0 -8
- package/dist/service-adapters/shared/index.mjs.map +0 -1
- package/src/lib/error-messages.ts +0 -200
- package/src/lib/runtime/__tests__/copilot-runtime-trace.test.ts +0 -169
- package/src/service-adapters/shared/error-utils.ts +0 -61
- package/src/service-adapters/shared/index.ts +0 -1
- package/dist/{chunk-TOBFVWZU.mjs.map → chunk-6TQCQ3WJ.mjs.map} +0 -0
- package/dist/{chunk-VBXBFZEL.mjs.map → chunk-CD2SZGIZ.mjs.map} +0 -0
- package/dist/{chunk-6RUTA76W.mjs.map → chunk-D3SPXEVJ.mjs.map} +0 -0
- package/dist/{langserve-fc5cac89.d.ts → langserve-4a5c9217.d.ts} +7 -7
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error message configuration - Single source of truth for all error messages
|
|
3
|
-
*
|
|
4
|
-
* This centralized configuration system provides:
|
|
5
|
-
*
|
|
6
|
-
* 🎯 **Benefits:**
|
|
7
|
-
* - Single source of truth for all error messages
|
|
8
|
-
* - Easy content management without touching code
|
|
9
|
-
* - Consistent error messaging across the application
|
|
10
|
-
* - Ready for internationalization (i18n)
|
|
11
|
-
* - Type-safe configuration with TypeScript
|
|
12
|
-
* - Categorized errors for better handling
|
|
13
|
-
*
|
|
14
|
-
* 📝 **How to use:**
|
|
15
|
-
* 1. Add new error patterns to `errorPatterns` object
|
|
16
|
-
* 2. Use {context} placeholder for dynamic context injection
|
|
17
|
-
* 3. Specify category, severity, and actionable flags
|
|
18
|
-
* 4. Add fallback messages for error categories
|
|
19
|
-
*
|
|
20
|
-
* 🔧 **How to maintain:**
|
|
21
|
-
* - Content teams can update messages here without touching logic
|
|
22
|
-
* - Developers add new error patterns as needed
|
|
23
|
-
* - Use categories to group similar errors
|
|
24
|
-
* - Mark errors as actionable if users can fix them
|
|
25
|
-
*
|
|
26
|
-
* 🌍 **Future i18n support:**
|
|
27
|
-
* - Replace `message` string with `messages: { en: "...", es: "..." }`
|
|
28
|
-
* - Add locale parameter to helper functions
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Adding a new error pattern:
|
|
33
|
-
* "CUSTOM_ERROR": {
|
|
34
|
-
* message: "Custom error occurred in {context}. Please try again.",
|
|
35
|
-
* category: "unknown",
|
|
36
|
-
* severity: "error",
|
|
37
|
-
* actionable: true
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
export interface ErrorPatternConfig {
|
|
43
|
-
message: string;
|
|
44
|
-
category: "network" | "connection" | "authentication" | "validation" | "unknown";
|
|
45
|
-
severity: "error" | "warning" | "info";
|
|
46
|
-
actionable: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface ErrorConfig {
|
|
50
|
-
errorPatterns: Record<string, ErrorPatternConfig>;
|
|
51
|
-
fallbacks: Record<string, string>;
|
|
52
|
-
contextTemplates: Record<string, string>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const errorConfig: ErrorConfig = {
|
|
56
|
-
errorPatterns: {
|
|
57
|
-
ECONNREFUSED: {
|
|
58
|
-
message:
|
|
59
|
-
"Connection refused - the agent service is not running or not accessible at the specified address. Please check that your agent is started and listening on the correct port.",
|
|
60
|
-
category: "network",
|
|
61
|
-
severity: "error",
|
|
62
|
-
actionable: true,
|
|
63
|
-
},
|
|
64
|
-
ENOTFOUND: {
|
|
65
|
-
message:
|
|
66
|
-
"Host not found - the agent service URL appears to be incorrect or the service is not accessible. Please verify the agent endpoint URL.",
|
|
67
|
-
category: "network",
|
|
68
|
-
severity: "error",
|
|
69
|
-
actionable: true,
|
|
70
|
-
},
|
|
71
|
-
ETIMEDOUT: {
|
|
72
|
-
message:
|
|
73
|
-
"Connection timeout - the agent service is taking too long to respond. This could indicate network issues or an overloaded agent service.",
|
|
74
|
-
category: "network",
|
|
75
|
-
severity: "warning",
|
|
76
|
-
actionable: true,
|
|
77
|
-
},
|
|
78
|
-
terminated: {
|
|
79
|
-
message:
|
|
80
|
-
"Agent {context} was unexpectedly terminated. This often indicates an error in the agent service (e.g., authentication failures, missing environment variables, or agent crashes). Check the agent logs for the root cause.",
|
|
81
|
-
category: "connection",
|
|
82
|
-
severity: "error",
|
|
83
|
-
actionable: true,
|
|
84
|
-
},
|
|
85
|
-
UND_ERR_SOCKET: {
|
|
86
|
-
message:
|
|
87
|
-
"Socket connection was closed unexpectedly. This typically indicates the agent service encountered an error and shut down the connection. Check the agent logs for the underlying cause.",
|
|
88
|
-
category: "connection",
|
|
89
|
-
severity: "error",
|
|
90
|
-
actionable: true,
|
|
91
|
-
},
|
|
92
|
-
other_side_closed: {
|
|
93
|
-
message:
|
|
94
|
-
"The agent service closed the connection unexpectedly. This usually indicates an error in the agent service. Check the agent logs for more details.",
|
|
95
|
-
category: "connection",
|
|
96
|
-
severity: "error",
|
|
97
|
-
actionable: true,
|
|
98
|
-
},
|
|
99
|
-
fetch_failed: {
|
|
100
|
-
message:
|
|
101
|
-
"Failed to connect to the agent service. Please verify the agent is running and the endpoint URL is correct.",
|
|
102
|
-
category: "network",
|
|
103
|
-
severity: "error",
|
|
104
|
-
actionable: true,
|
|
105
|
-
},
|
|
106
|
-
// Authentication patterns
|
|
107
|
-
"401": {
|
|
108
|
-
message:
|
|
109
|
-
"Authentication failed. Please check your API keys and ensure they are correctly configured.",
|
|
110
|
-
category: "authentication",
|
|
111
|
-
severity: "error",
|
|
112
|
-
actionable: true,
|
|
113
|
-
},
|
|
114
|
-
"api key": {
|
|
115
|
-
message:
|
|
116
|
-
"API key error detected. Please verify your API key is correct and has the necessary permissions.",
|
|
117
|
-
category: "authentication",
|
|
118
|
-
severity: "error",
|
|
119
|
-
actionable: true,
|
|
120
|
-
},
|
|
121
|
-
unauthorized: {
|
|
122
|
-
message: "Unauthorized access. Please check your authentication credentials.",
|
|
123
|
-
category: "authentication",
|
|
124
|
-
severity: "error",
|
|
125
|
-
actionable: true,
|
|
126
|
-
},
|
|
127
|
-
// Python-specific error patterns
|
|
128
|
-
AuthenticationError: {
|
|
129
|
-
message:
|
|
130
|
-
"OpenAI authentication failed. Please check your OPENAI_API_KEY environment variable or API key configuration.",
|
|
131
|
-
category: "authentication",
|
|
132
|
-
severity: "error",
|
|
133
|
-
actionable: true,
|
|
134
|
-
},
|
|
135
|
-
"Incorrect API key provided": {
|
|
136
|
-
message:
|
|
137
|
-
"OpenAI API key is invalid. Please verify your OPENAI_API_KEY is correct and active.",
|
|
138
|
-
category: "authentication",
|
|
139
|
-
severity: "error",
|
|
140
|
-
actionable: true,
|
|
141
|
-
},
|
|
142
|
-
RateLimitError: {
|
|
143
|
-
message:
|
|
144
|
-
"OpenAI rate limit exceeded. Please wait a moment and try again, or check your OpenAI usage limits.",
|
|
145
|
-
category: "network",
|
|
146
|
-
severity: "warning",
|
|
147
|
-
actionable: true,
|
|
148
|
-
},
|
|
149
|
-
InvalidRequestError: {
|
|
150
|
-
message:
|
|
151
|
-
"Invalid request to OpenAI API. Please check your request parameters and model configuration.",
|
|
152
|
-
category: "validation",
|
|
153
|
-
severity: "error",
|
|
154
|
-
actionable: true,
|
|
155
|
-
},
|
|
156
|
-
PermissionDeniedError: {
|
|
157
|
-
message:
|
|
158
|
-
"Permission denied for OpenAI API. Please check your API key permissions and billing status.",
|
|
159
|
-
category: "authentication",
|
|
160
|
-
severity: "error",
|
|
161
|
-
actionable: true,
|
|
162
|
-
},
|
|
163
|
-
NotFoundError: {
|
|
164
|
-
message: "OpenAI resource not found. Please check your model name and availability.",
|
|
165
|
-
category: "validation",
|
|
166
|
-
severity: "error",
|
|
167
|
-
actionable: true,
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
fallbacks: {
|
|
171
|
-
network:
|
|
172
|
-
"A network error occurred while connecting to the agent service. Please check your connection and ensure the agent service is running.",
|
|
173
|
-
connection:
|
|
174
|
-
"The connection to the agent service was lost unexpectedly. This may indicate an issue with the agent service.",
|
|
175
|
-
authentication: "Authentication failed. Please check your API keys and credentials.",
|
|
176
|
-
validation: "Invalid input or configuration. Please check your parameters and try again.",
|
|
177
|
-
unknown: "An unexpected error occurred. Please check the logs for more details.",
|
|
178
|
-
default: "An unexpected error occurred. Please check the logs for more details.",
|
|
179
|
-
},
|
|
180
|
-
contextTemplates: {
|
|
181
|
-
connection: "connection",
|
|
182
|
-
event_streaming_connection: "event streaming connection",
|
|
183
|
-
agent_streaming_connection: "agent streaming connection",
|
|
184
|
-
langgraph_agent_connection: "LangGraph agent connection",
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Helper function to get error pattern configuration by key
|
|
190
|
-
*/
|
|
191
|
-
export function getErrorPattern(key: string): ErrorPatternConfig | undefined {
|
|
192
|
-
return errorConfig.errorPatterns[key];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Helper function to get fallback message by category
|
|
197
|
-
*/
|
|
198
|
-
export function getFallbackMessage(category: string): string {
|
|
199
|
-
return errorConfig.fallbacks[category] || errorConfig.fallbacks.default;
|
|
200
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { CopilotTraceEvent, CopilotRequestContext, CopilotTraceHandler } from "@copilotkit/shared";
|
|
2
|
-
|
|
3
|
-
describe("CopilotRuntime onTrace types", () => {
|
|
4
|
-
it("should have correct CopilotTraceEvent type structure", () => {
|
|
5
|
-
const traceEvent: CopilotTraceEvent = {
|
|
6
|
-
type: "error",
|
|
7
|
-
timestamp: Date.now(),
|
|
8
|
-
context: {
|
|
9
|
-
threadId: "test-123",
|
|
10
|
-
source: "runtime",
|
|
11
|
-
request: {
|
|
12
|
-
operation: "test-operation",
|
|
13
|
-
startTime: Date.now(),
|
|
14
|
-
},
|
|
15
|
-
technical: {},
|
|
16
|
-
metadata: {},
|
|
17
|
-
},
|
|
18
|
-
error: new Error("Test error"),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
expect(traceEvent.type).toBe("error");
|
|
22
|
-
expect(traceEvent.timestamp).toBeGreaterThan(0);
|
|
23
|
-
expect(traceEvent.context.threadId).toBe("test-123");
|
|
24
|
-
expect(traceEvent.error).toBeInstanceOf(Error);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should have correct CopilotRequestContext type structure", () => {
|
|
28
|
-
const context: CopilotRequestContext = {
|
|
29
|
-
threadId: "test-thread-456",
|
|
30
|
-
runId: "test-run-789",
|
|
31
|
-
source: "runtime",
|
|
32
|
-
request: {
|
|
33
|
-
operation: "processRuntimeRequest",
|
|
34
|
-
method: "POST",
|
|
35
|
-
url: "http://localhost:3000/api/copilotkit",
|
|
36
|
-
startTime: Date.now(),
|
|
37
|
-
},
|
|
38
|
-
response: {
|
|
39
|
-
status: 200,
|
|
40
|
-
endTime: Date.now(),
|
|
41
|
-
latency: 1200,
|
|
42
|
-
},
|
|
43
|
-
agent: {
|
|
44
|
-
name: "test-agent",
|
|
45
|
-
nodeName: "test-node",
|
|
46
|
-
state: { step: 1 },
|
|
47
|
-
},
|
|
48
|
-
messages: {
|
|
49
|
-
input: [],
|
|
50
|
-
output: [],
|
|
51
|
-
messageCount: 2,
|
|
52
|
-
},
|
|
53
|
-
technical: {
|
|
54
|
-
userAgent: "Mozilla/5.0...",
|
|
55
|
-
host: "localhost:3000",
|
|
56
|
-
environment: "test",
|
|
57
|
-
version: "1.0.0",
|
|
58
|
-
stackTrace: "Error: Test\n at test.js:1:1",
|
|
59
|
-
},
|
|
60
|
-
performance: {
|
|
61
|
-
requestDuration: 1200,
|
|
62
|
-
streamingDuration: 800,
|
|
63
|
-
actionExecutionTime: 400,
|
|
64
|
-
memoryUsage: 45.2,
|
|
65
|
-
},
|
|
66
|
-
metadata: {
|
|
67
|
-
testFlag: true,
|
|
68
|
-
version: "1.0.0",
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
expect(context.threadId).toBe("test-thread-456");
|
|
73
|
-
expect(context.agent?.name).toBe("test-agent");
|
|
74
|
-
expect(context.messages?.messageCount).toBe(2);
|
|
75
|
-
expect(context.technical?.stackTrace).toContain("Error: Test");
|
|
76
|
-
expect(context.metadata?.testFlag).toBe(true);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should support all trace event types", () => {
|
|
80
|
-
const eventTypes: CopilotTraceEvent["type"][] = [
|
|
81
|
-
"error",
|
|
82
|
-
"request",
|
|
83
|
-
"response",
|
|
84
|
-
"agent_state",
|
|
85
|
-
"action",
|
|
86
|
-
"message",
|
|
87
|
-
"performance",
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
eventTypes.forEach((type) => {
|
|
91
|
-
const event: CopilotTraceEvent = {
|
|
92
|
-
type,
|
|
93
|
-
timestamp: Date.now(),
|
|
94
|
-
context: {
|
|
95
|
-
threadId: `test-${type}`,
|
|
96
|
-
source: "runtime",
|
|
97
|
-
request: {
|
|
98
|
-
operation: "test",
|
|
99
|
-
startTime: Date.now(),
|
|
100
|
-
},
|
|
101
|
-
technical: {},
|
|
102
|
-
metadata: {},
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
expect(event.type).toBe(type);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("publicApiKey gating logic", () => {
|
|
111
|
-
type ShouldTrace = (onTrace?: CopilotTraceHandler, publicApiKey?: string) => boolean;
|
|
112
|
-
|
|
113
|
-
const shouldTrace: ShouldTrace = (onTrace, publicApiKey) => {
|
|
114
|
-
return Boolean(onTrace && publicApiKey);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
it("should return true when both onTrace and publicApiKey are provided", () => {
|
|
118
|
-
const onTrace = jest.fn();
|
|
119
|
-
const result = shouldTrace(onTrace, "valid-api-key");
|
|
120
|
-
expect(result).toBe(true);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should return false when onTrace is missing", () => {
|
|
124
|
-
const result = shouldTrace(undefined, "valid-api-key");
|
|
125
|
-
expect(result).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("should return false when publicApiKey is missing", () => {
|
|
129
|
-
const onTrace = jest.fn();
|
|
130
|
-
const result = shouldTrace(onTrace, undefined);
|
|
131
|
-
expect(result).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should return false when publicApiKey is empty string", () => {
|
|
135
|
-
const onTrace = jest.fn();
|
|
136
|
-
const result = shouldTrace(onTrace, "");
|
|
137
|
-
expect(result).toBe(false);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("should return false when both are missing", () => {
|
|
141
|
-
const result = shouldTrace(undefined, undefined);
|
|
142
|
-
expect(result).toBe(false);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should extract publicApiKey from headers for both cloud and non-cloud requests", () => {
|
|
146
|
-
// Test the logic we just fixed in the GraphQL resolver
|
|
147
|
-
const mockHeaders = new Map([["x-copilotcloud-public-api-key", "test-key-123"]]);
|
|
148
|
-
|
|
149
|
-
// Simulate header extraction logic
|
|
150
|
-
const extractPublicApiKey = (headers: Map<string, string>, hasCloudConfig: boolean) => {
|
|
151
|
-
const publicApiKeyFromHeaders = headers.get("x-copilotcloud-public-api-key");
|
|
152
|
-
return publicApiKeyFromHeaders || null;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Should work for cloud requests
|
|
156
|
-
const cloudKey = extractPublicApiKey(mockHeaders, true);
|
|
157
|
-
expect(cloudKey).toBe("test-key-123");
|
|
158
|
-
|
|
159
|
-
// Should also work for non-cloud requests (this was the bug)
|
|
160
|
-
const nonCloudKey = extractPublicApiKey(mockHeaders, false);
|
|
161
|
-
expect(nonCloudKey).toBe("test-key-123");
|
|
162
|
-
|
|
163
|
-
// Both should enable tracing when onTrace is present
|
|
164
|
-
const onTrace = jest.fn();
|
|
165
|
-
expect(shouldTrace(onTrace, cloudKey)).toBe(true);
|
|
166
|
-
expect(shouldTrace(onTrace, nonCloudKey)).toBe(true);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { CopilotKitLowLevelError, CopilotKitErrorCode } 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
|
-
export function convertServiceAdapterError(
|
|
8
|
-
error: any,
|
|
9
|
-
adapterName: string,
|
|
10
|
-
): CopilotKitLowLevelError {
|
|
11
|
-
const errorName = error?.constructor?.name || error.name;
|
|
12
|
-
const errorMessage = error?.message || String(error);
|
|
13
|
-
const statusCode = error.status || error.statusCode || error.response?.status;
|
|
14
|
-
const responseData = error.error || error.response?.data || error.data;
|
|
15
|
-
|
|
16
|
-
// Create the base error with the constructor signature
|
|
17
|
-
const structuredError = new CopilotKitLowLevelError({
|
|
18
|
-
error: error instanceof Error ? error : new Error(errorMessage),
|
|
19
|
-
url: `${adapterName} service adapter`,
|
|
20
|
-
message: `${adapterName} API error: ${errorMessage}`,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Add additional properties after construction
|
|
24
|
-
if (statusCode) {
|
|
25
|
-
(structuredError as any).statusCode = statusCode;
|
|
26
|
-
}
|
|
27
|
-
if (responseData) {
|
|
28
|
-
(structuredError as any).responseData = responseData;
|
|
29
|
-
}
|
|
30
|
-
if (errorName) {
|
|
31
|
-
(structuredError as any).originalErrorType = errorName;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Classify error based on HTTP status codes (reliable and provider-agnostic)
|
|
35
|
-
let newCode: CopilotKitErrorCode;
|
|
36
|
-
|
|
37
|
-
if (statusCode === 401) {
|
|
38
|
-
// 401 = Authentication/API key issues
|
|
39
|
-
newCode = CopilotKitErrorCode.AUTHENTICATION_ERROR;
|
|
40
|
-
} else if (statusCode >= 400 && statusCode < 500) {
|
|
41
|
-
// 4xx = Client errors (bad request, invalid params, etc.) - these are configuration issues
|
|
42
|
-
newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
|
|
43
|
-
} else if (statusCode >= 500) {
|
|
44
|
-
// 5xx = Server errors - keep as NETWORK_ERROR since it's infrastructure related
|
|
45
|
-
newCode = CopilotKitErrorCode.NETWORK_ERROR;
|
|
46
|
-
} else if (statusCode) {
|
|
47
|
-
// Any other HTTP status with an error - likely configuration
|
|
48
|
-
newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
|
|
49
|
-
} else {
|
|
50
|
-
// No status code - likely a genuine network/connection error
|
|
51
|
-
newCode = CopilotKitErrorCode.NETWORK_ERROR;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Update both the instance property and the extensions
|
|
55
|
-
(structuredError as any).code = newCode;
|
|
56
|
-
if ((structuredError as any).extensions) {
|
|
57
|
-
(structuredError as any).extensions.code = newCode;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return structuredError;
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./error-utils";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,13 +3,6 @@ import * as rxjs from 'rxjs';
|
|
|
3
3
|
import { Subject, ReplaySubject } from 'rxjs';
|
|
4
4
|
import { Action, Parameter } from '@copilotkit/shared';
|
|
5
5
|
|
|
6
|
-
declare class ActionInput {
|
|
7
|
-
name: string;
|
|
8
|
-
description: string;
|
|
9
|
-
jsonSchema: string;
|
|
10
|
-
available?: ActionInputAvailability;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
declare enum GuardrailsResultStatus {
|
|
14
7
|
ALLOWED = "allowed",
|
|
15
8
|
DENIED = "denied"
|
|
@@ -19,6 +12,13 @@ declare class GuardrailsResult {
|
|
|
19
12
|
reason?: string;
|
|
20
13
|
}
|
|
21
14
|
|
|
15
|
+
declare class ActionInput {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
jsonSchema: string;
|
|
19
|
+
available?: ActionInputAvailability;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
declare enum RuntimeEventTypes {
|
|
23
23
|
TextMessageStart = "TextMessageStart",
|
|
24
24
|
TextMessageContent = "TextMessageContent",
|