@copilotkit/shared 1.5.12-next.4 → 1.5.12-next.6

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@copilotkit/shared\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.5.12-next.4\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"dev\": \"tsup --watch --no-splitting\",\n \"test\": \"jest --passWithNoTests\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.4\",\n \"@types/uuid\": \"^10.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-custom\": \"workspace:*\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"tsconfig\": \"workspace:*\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.2.3\"\n },\n \"dependencies\": {\n \"@segment/analytics-node\": \"^2.1.2\",\n \"chalk\": \"4.1.2\",\n \"uuid\": \"^10.0.0\",\n \"zod\": \"^3.23.3\",\n \"zod-to-json-schema\": \"^3.23.5\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n","export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWE,cAAW;;;ACLN,IAAM,qBAAiC;","names":[]}
1
+ {"version":3,"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@copilotkit/shared\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.5.12-next.6\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"dev\": \"tsup --watch --no-splitting\",\n \"test\": \"jest --passWithNoTests\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.4\",\n \"@types/uuid\": \"^10.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-custom\": \"workspace:*\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"tsconfig\": \"workspace:*\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.2.3\"\n },\n \"dependencies\": {\n \"@segment/analytics-node\": \"^2.1.2\",\n \"chalk\": \"4.1.2\",\n \"graphql\": \"^16.8.1\",\n \"uuid\": \"^10.0.0\",\n \"zod\": \"^3.23.3\",\n \"zod-to-json-schema\": \"^3.23.5\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n","export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWE,cAAW;;;ACLN,IAAM,qBAAiC;","names":[]}
@@ -0,0 +1,155 @@
1
+ import { GraphQLError } from 'graphql';
2
+
3
+ declare const ERROR_NAMES: {
4
+ readonly COPILOT_ERROR: "CopilotError";
5
+ readonly COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError";
6
+ readonly COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError";
7
+ readonly COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError";
8
+ readonly COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError";
9
+ readonly RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError";
10
+ };
11
+ declare enum CopilotKitErrorCode {
12
+ NETWORK_ERROR = "NETWORK_ERROR",
13
+ NOT_FOUND = "NOT_FOUND",
14
+ AGENT_NOT_FOUND = "AGENT_NOT_FOUND",
15
+ API_NOT_FOUND = "API_NOT_FOUND",
16
+ REMOTE_ENDPOINT_NOT_FOUND = "REMOTE_ENDPOINT_NOT_FOUND",
17
+ MISUSE = "MISUSE",
18
+ UNKNOWN = "UNKNOWN"
19
+ }
20
+ declare const ERROR_CONFIG: {
21
+ NETWORK_ERROR: {
22
+ statusCode: number;
23
+ troubleshootingUrl: string;
24
+ };
25
+ NOT_FOUND: {
26
+ statusCode: number;
27
+ troubleshootingUrl: string;
28
+ };
29
+ AGENT_NOT_FOUND: {
30
+ statusCode: number;
31
+ troubleshootingUrl: string;
32
+ };
33
+ API_NOT_FOUND: {
34
+ statusCode: number;
35
+ troubleshootingUrl: string;
36
+ };
37
+ REMOTE_ENDPOINT_NOT_FOUND: {
38
+ statusCode: number;
39
+ troubleshootingUrl: string;
40
+ };
41
+ MISUSE: {
42
+ statusCode: number;
43
+ troubleshootingUrl: null;
44
+ };
45
+ UNKNOWN: {
46
+ statusCode: number;
47
+ };
48
+ };
49
+ declare class CopilotKitError extends GraphQLError {
50
+ code: CopilotKitErrorCode;
51
+ statusCode: number;
52
+ constructor({ message, code, }: {
53
+ message?: string;
54
+ code: CopilotKitErrorCode;
55
+ });
56
+ }
57
+ /**
58
+ * Error thrown when we can identify wrong usage of our components.
59
+ * This helps us notify the developer before real errors can happen
60
+ *
61
+ * @extends CopilotKitError
62
+ */
63
+ declare class CopilotKitMisuseError extends CopilotKitError {
64
+ constructor({ message, code, }: {
65
+ message: string;
66
+ code?: CopilotKitErrorCode;
67
+ });
68
+ }
69
+ /**
70
+ * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
71
+ * This typically occurs when:
72
+ * - The API endpoint URL is invalid or misconfigured
73
+ * - The API service is not running at the expected location
74
+ * - There are network/firewall issues preventing access
75
+ *
76
+ * @extends CopilotKitError
77
+ */
78
+ declare class CopilotKitApiDiscoveryError extends CopilotKitError {
79
+ constructor(params?: {
80
+ message?: string;
81
+ code?: CopilotKitErrorCode.API_NOT_FOUND | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;
82
+ });
83
+ }
84
+ /**
85
+ * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted
86
+ * This typically occurs when:
87
+ * - The API endpoint URL is invalid or misconfigured
88
+ * - The API service is not running at the expected location
89
+ *
90
+ * @extends CopilotKitApiDiscoveryError
91
+ */
92
+ declare class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {
93
+ constructor(params?: {
94
+ message?: string;
95
+ });
96
+ }
97
+ /**
98
+ * Error thrown when a LangGraph agent cannot be found or accessed.
99
+ * This typically occurs when:
100
+ * - The specified agent name does not exist in the deployment
101
+ * - The agent configuration is invalid or missing
102
+ * - The agent service is not properly deployed or initialized
103
+ *
104
+ * @extends CopilotKitError
105
+ */
106
+ declare class CopilotKitAgentDiscoveryError extends CopilotKitError {
107
+ constructor(params?: {
108
+ agentName?: string;
109
+ });
110
+ }
111
+ /**
112
+ * Handles low-level networking errors that occur before a request reaches the server.
113
+ * These errors arise from issues in the underlying communication infrastructure rather than
114
+ * application-level logic or server responses. Typically used to handle "fetch failed" errors
115
+ * where no HTTP status code is available.
116
+ *
117
+ * Common scenarios include:
118
+ * - Connection failures (ECONNREFUSED) when server is down/unreachable
119
+ * - DNS resolution failures (ENOTFOUND) when domain can't be resolved
120
+ * - Timeouts (ETIMEDOUT) when request takes too long
121
+ * - Protocol/transport layer errors like SSL/TLS issues
122
+ */
123
+ declare class CopilotKitLowLevelError extends CopilotKitError {
124
+ constructor({ error, url, message }: {
125
+ error: Error;
126
+ url: string;
127
+ message?: string;
128
+ });
129
+ }
130
+ /**
131
+ * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.
132
+ * Used when we receive an HTTP error status and wish to handle broad range of them
133
+ *
134
+ * This differs from CopilotKitLowLevelError in that:
135
+ * - ResolvedCopilotKitError: Server was reached and returned an HTTP status
136
+ * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)
137
+ *
138
+ * @param status - The HTTP status code received from the API response
139
+ * @param message - Optional error message to include
140
+ * @param code - Optional specific CopilotKitErrorCode to override default behavior
141
+ *
142
+ * Default behavior:
143
+ * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError
144
+ * - All other status codes: Maps to UNKNOWN error code if no specific code provided
145
+ */
146
+ declare class ResolvedCopilotKitError extends CopilotKitError {
147
+ constructor({ status, message, code, isRemoteEndpoint, }: {
148
+ status: number;
149
+ message?: string;
150
+ code?: CopilotKitErrorCode;
151
+ isRemoteEndpoint?: boolean;
152
+ });
153
+ }
154
+
155
+ export { CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ResolvedCopilotKitError };
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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/utils/errors.ts
21
+ var errors_exports = {};
22
+ __export(errors_exports, {
23
+ CopilotKitAgentDiscoveryError: () => CopilotKitAgentDiscoveryError,
24
+ CopilotKitApiDiscoveryError: () => CopilotKitApiDiscoveryError,
25
+ CopilotKitError: () => CopilotKitError,
26
+ CopilotKitErrorCode: () => CopilotKitErrorCode,
27
+ CopilotKitLowLevelError: () => CopilotKitLowLevelError,
28
+ CopilotKitMisuseError: () => CopilotKitMisuseError,
29
+ CopilotKitRemoteEndpointDiscoveryError: () => CopilotKitRemoteEndpointDiscoveryError,
30
+ ERROR_CONFIG: () => ERROR_CONFIG,
31
+ ERROR_NAMES: () => ERROR_NAMES,
32
+ ResolvedCopilotKitError: () => ResolvedCopilotKitError
33
+ });
34
+ module.exports = __toCommonJS(errors_exports);
35
+ var import_graphql = require("graphql");
36
+ var ERROR_NAMES = {
37
+ COPILOT_ERROR: "CopilotError",
38
+ COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
39
+ COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
40
+ COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
41
+ COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
42
+ RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError"
43
+ };
44
+ var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
45
+ CopilotKitErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
46
+ CopilotKitErrorCode2["NOT_FOUND"] = "NOT_FOUND";
47
+ CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
48
+ CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
49
+ CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
50
+ CopilotKitErrorCode2["MISUSE"] = "MISUSE";
51
+ CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
52
+ return CopilotKitErrorCode2;
53
+ })(CopilotKitErrorCode || {});
54
+ var BASE_URL = "https://docs.copilotkit.ai";
55
+ var getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
56
+ var ERROR_CONFIG = {
57
+ ["NETWORK_ERROR" /* NETWORK_ERROR */]: {
58
+ statusCode: 503,
59
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
60
+ },
61
+ ["NOT_FOUND" /* NOT_FOUND */]: {
62
+ statusCode: 404,
63
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
64
+ },
65
+ ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
66
+ statusCode: 500,
67
+ troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`
68
+ },
69
+ ["API_NOT_FOUND" /* API_NOT_FOUND */]: {
70
+ statusCode: 404,
71
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
72
+ },
73
+ ["REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */]: {
74
+ statusCode: 404,
75
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`
76
+ },
77
+ ["MISUSE" /* MISUSE */]: {
78
+ statusCode: 400,
79
+ troubleshootingUrl: null
80
+ },
81
+ ["UNKNOWN" /* UNKNOWN */]: {
82
+ statusCode: 500
83
+ }
84
+ };
85
+ var CopilotKitError = class extends import_graphql.GraphQLError {
86
+ constructor({
87
+ message = "Unknown error occurred",
88
+ code
89
+ }) {
90
+ const name = ERROR_NAMES.COPILOT_ERROR;
91
+ const { statusCode } = ERROR_CONFIG[code];
92
+ super(message, {
93
+ extensions: {
94
+ name,
95
+ statusCode
96
+ }
97
+ });
98
+ this.code = code;
99
+ this.name = name;
100
+ this.statusCode = statusCode;
101
+ }
102
+ };
103
+ var CopilotKitMisuseError = class extends CopilotKitError {
104
+ constructor({
105
+ message,
106
+ code = "MISUSE" /* MISUSE */
107
+ }) {
108
+ const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
109
+ const finalMessage = docsLink ? `${message}.
110
+
111
+ ${docsLink}` : message;
112
+ super({ message: finalMessage, code });
113
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
114
+ }
115
+ };
116
+ var CopilotKitApiDiscoveryError = class extends CopilotKitError {
117
+ constructor(params = {}) {
118
+ const message = params.message ?? "Failed to find CopilotKit API endpoint";
119
+ const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
120
+ const errorMessage = `${message}.
121
+
122
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
123
+ super({ message: errorMessage, code });
124
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
125
+ }
126
+ };
127
+ var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
128
+ constructor(params) {
129
+ const message = (params == null ? void 0 : params.message) ?? "Failed to find or contact remote endpoint";
130
+ const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
131
+ super({ message, code });
132
+ this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
133
+ }
134
+ };
135
+ var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
136
+ constructor(params) {
137
+ const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
138
+ const baseMessage = "Failed to find agent";
139
+ const configMessage = "Please verify the agent name exists and is properly configured.";
140
+ const finalMessage = (params == null ? void 0 : params.agentName) ? `${baseMessage} '${params.agentName}'. ${configMessage}
141
+
142
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}` : `${baseMessage}. ${configMessage}
143
+
144
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
145
+ super({ message: finalMessage || finalMessage, code });
146
+ this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
147
+ }
148
+ };
149
+ var CopilotKitLowLevelError = class extends CopilotKitError {
150
+ constructor({ error, url, message }) {
151
+ let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
152
+ const getMessageByCode = (errorCode) => {
153
+ const troubleshootingLink = ERROR_CONFIG[code].troubleshootingUrl;
154
+ switch (errorCode) {
155
+ case "ECONNREFUSED":
156
+ return `Connection to ${url} was refused. Ensure the server is running and accessible.
157
+
158
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
159
+ case "ENOTFOUND":
160
+ return `The server on ${url} could not be found. Check the URL or your network configuration.
161
+
162
+ ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
163
+ case "ETIMEDOUT":
164
+ return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
165
+
166
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
167
+ default:
168
+ return `Failed to fetch from url ${url}.
169
+
170
+ Possible reasons:
171
+ - -The server might be down or unreachable
172
+ - -There might be a network issue (e.g., DNS failure, connection timeout)
173
+ - -The URL might be incorrect
174
+ - -The server is not running on the specified port
175
+
176
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
177
+ }
178
+ };
179
+ const errorMessage = message ?? getMessageByCode(error.code);
180
+ super({ message: errorMessage, code });
181
+ this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
182
+ }
183
+ };
184
+ var ResolvedCopilotKitError = class extends CopilotKitError {
185
+ constructor({
186
+ status,
187
+ message,
188
+ code,
189
+ isRemoteEndpoint
190
+ }) {
191
+ let resolvedCode = code;
192
+ if (!resolvedCode) {
193
+ switch (status) {
194
+ case 400:
195
+ throw new CopilotKitApiDiscoveryError({ message });
196
+ case 404:
197
+ throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message }) : new CopilotKitApiDiscoveryError({ message });
198
+ default:
199
+ resolvedCode = "UNKNOWN" /* UNKNOWN */;
200
+ super({ message, code: resolvedCode });
201
+ }
202
+ } else {
203
+ super({ message, code: resolvedCode });
204
+ }
205
+ this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
206
+ }
207
+ };
208
+ // Annotate the CommonJS export names for ESM import in node:
209
+ 0 && (module.exports = {
210
+ CopilotKitAgentDiscoveryError,
211
+ CopilotKitApiDiscoveryError,
212
+ CopilotKitError,
213
+ CopilotKitErrorCode,
214
+ CopilotKitLowLevelError,
215
+ CopilotKitMisuseError,
216
+ CopilotKitRemoteEndpointDiscoveryError,
217
+ ERROR_CONFIG,
218
+ ERROR_NAMES,
219
+ ResolvedCopilotKitError
220
+ });
221
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/errors.ts"],"sourcesContent":["import { GraphQLError } from \"graphql\";\n\nexport const ERROR_NAMES = {\n COPILOT_ERROR: \"CopilotError\",\n COPILOT_API_DISCOVERY_ERROR: \"CopilotApiDiscoveryError\",\n COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: \"CopilotKitRemoteEndpointDiscoveryError\",\n COPILOT_KIT_AGENT_DISCOVERY_ERROR: \"CopilotKitAgentDiscoveryError\",\n COPILOT_KIT_LOW_LEVEL_ERROR: \"CopilotKitLowLevelError\",\n RESOLVED_COPILOT_KIT_ERROR: \"ResolvedCopilotKitError\",\n} as const;\n\nexport enum CopilotKitErrorCode {\n NETWORK_ERROR = \"NETWORK_ERROR\",\n NOT_FOUND = \"NOT_FOUND\",\n AGENT_NOT_FOUND = \"AGENT_NOT_FOUND\",\n API_NOT_FOUND = \"API_NOT_FOUND\",\n REMOTE_ENDPOINT_NOT_FOUND = \"REMOTE_ENDPOINT_NOT_FOUND\",\n MISUSE = \"MISUSE\",\n UNKNOWN = \"UNKNOWN\",\n}\n\nconst BASE_URL = \"https://docs.copilotkit.ai\";\n\nconst getSeeMoreMarkdown = (link: string) => `See more: [${link}](${link})`;\n\nexport const ERROR_CONFIG = {\n [CopilotKitErrorCode.NETWORK_ERROR]: {\n statusCode: 503,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n },\n [CopilotKitErrorCode.NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n },\n [CopilotKitErrorCode.AGENT_NOT_FOUND]: {\n statusCode: 500,\n troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,\n },\n [CopilotKitErrorCode.API_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n },\n [CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,\n },\n [CopilotKitErrorCode.MISUSE]: {\n statusCode: 400,\n troubleshootingUrl: null,\n },\n [CopilotKitErrorCode.UNKNOWN]: {\n statusCode: 500,\n },\n};\n\nexport class CopilotKitError extends GraphQLError {\n code: CopilotKitErrorCode;\n statusCode: number;\n\n constructor({\n message = \"Unknown error occurred\",\n code,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n }) {\n const name = ERROR_NAMES.COPILOT_ERROR;\n const { statusCode } = ERROR_CONFIG[code];\n\n super(message, {\n extensions: {\n name,\n statusCode,\n },\n });\n this.code = code;\n this.name = name;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Error thrown when we can identify wrong usage of our components.\n * This helps us notify the developer before real errors can happen\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitMisuseError extends CopilotKitError {\n constructor({\n message,\n code = CopilotKitErrorCode.MISUSE,\n }: {\n message: string;\n code?: CopilotKitErrorCode;\n }) {\n const docsLink =\n \"troubleshootingUrl\" in ERROR_CONFIG[code]\n ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl as string)\n : null;\n const finalMessage = docsLink ? `${message}.\\n\\n${docsLink}` : message;\n super({ message: finalMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n * - There are network/firewall issues preventing access\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitApiDiscoveryError extends CopilotKitError {\n constructor(\n params: {\n message?: string;\n code?: CopilotKitErrorCode.API_NOT_FOUND | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n } = {},\n ) {\n const message = params.message ?? \"Failed to find CopilotKit API endpoint\";\n const code = params.code ?? CopilotKitErrorCode.API_NOT_FOUND;\n const errorMessage = `${message}.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;\n super({ message: errorMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n *\n * @extends CopilotKitApiDiscoveryError\n */\nexport class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {\n constructor(params?: { message?: string }) {\n const message = params?.message ?? \"Failed to find or contact remote endpoint\";\n const code = CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when a LangGraph agent cannot be found or accessed.\n * This typically occurs when:\n * - The specified agent name does not exist in the deployment\n * - The agent configuration is invalid or missing\n * - The agent service is not properly deployed or initialized\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitAgentDiscoveryError extends CopilotKitError {\n constructor(params?: { agentName?: string }) {\n const code = CopilotKitErrorCode.AGENT_NOT_FOUND;\n const baseMessage = \"Failed to find agent\";\n const configMessage = \"Please verify the agent name exists and is properly configured.\";\n const finalMessage = params?.agentName\n ? `${baseMessage} '${params.agentName}'. ${configMessage}\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`\n : `${baseMessage}. ${configMessage}\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;\n super({ message: finalMessage || finalMessage, code });\n this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Handles low-level networking errors that occur before a request reaches the server.\n * These errors arise from issues in the underlying communication infrastructure rather than\n * application-level logic or server responses. Typically used to handle \"fetch failed\" errors\n * where no HTTP status code is available.\n *\n * Common scenarios include:\n * - Connection failures (ECONNREFUSED) when server is down/unreachable\n * - DNS resolution failures (ENOTFOUND) when domain can't be resolved\n * - Timeouts (ETIMEDOUT) when request takes too long\n * - Protocol/transport layer errors like SSL/TLS issues\n */\nexport class CopilotKitLowLevelError extends CopilotKitError {\n constructor({ error, url, message }: { error: Error; url: string; message?: string }) {\n let code = CopilotKitErrorCode.NETWORK_ERROR;\n\n const getMessageByCode = (errorCode?: string) => {\n const troubleshootingLink = ERROR_CONFIG[code].troubleshootingUrl;\n switch (errorCode) {\n case \"ECONNREFUSED\":\n return `Connection to ${url} was refused. Ensure the server is running and accessible.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n case \"ENOTFOUND\":\n return `The server on ${url} could not be found. Check the URL or your network configuration.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;\n case \"ETIMEDOUT\":\n return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n default:\n return `Failed to fetch from url ${url}.\n\nPossible reasons:\n- -The server might be down or unreachable\n- -There might be a network issue (e.g., DNS failure, connection timeout) \n- -The URL might be incorrect\n- -The server is not running on the specified port\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n }\n };\n // @ts-expect-error -- code may exist\n const errorMessage = message ?? getMessageByCode(error.code as string);\n\n super({ message: errorMessage, code });\n\n this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;\n }\n}\n\n/**\n * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.\n * Used when we receive an HTTP error status and wish to handle broad range of them\n *\n * This differs from CopilotKitLowLevelError in that:\n * - ResolvedCopilotKitError: Server was reached and returned an HTTP status\n * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)\n *\n * @param status - The HTTP status code received from the API response\n * @param message - Optional error message to include\n * @param code - Optional specific CopilotKitErrorCode to override default behavior\n *\n * Default behavior:\n * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError\n * - All other status codes: Maps to UNKNOWN error code if no specific code provided\n */\nexport class ResolvedCopilotKitError extends CopilotKitError {\n constructor({\n status,\n message,\n code,\n isRemoteEndpoint,\n }: {\n status: number;\n message?: string;\n code?: CopilotKitErrorCode;\n isRemoteEndpoint?: boolean;\n }) {\n let resolvedCode = code;\n if (!resolvedCode) {\n switch (status) {\n case 400:\n throw new CopilotKitApiDiscoveryError({ message });\n case 404:\n throw isRemoteEndpoint\n ? new CopilotKitRemoteEndpointDiscoveryError({ message })\n : new CopilotKitApiDiscoveryError({ message });\n default:\n resolvedCode = CopilotKitErrorCode.UNKNOWN;\n super({ message, code: resolvedCode });\n }\n } else {\n super({ message, code: resolvedCode });\n }\n this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAEtB,IAAM,cAAc;AAAA,EACzB,eAAe;AAAA,EACf,6BAA6B;AAAA,EAC7B,yCAAyC;AAAA,EACzC,mCAAmC;AAAA,EACnC,6BAA6B;AAAA,EAC7B,4BAA4B;AAC9B;AAEO,IAAK,sBAAL,kBAAKA,yBAAL;AACL,EAAAA,qBAAA,mBAAgB;AAChB,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,qBAAk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opilotKitErrorCode,
6
+ CopilotKitLowLevelError,
7
+ CopilotKitMisuseError,
8
+ CopilotKitRemoteEndpointDiscoveryError,
9
+ ERROR_CONFIG,
10
+ ERROR_NAMES,
11
+ ResolvedCopilotKitError
12
+ } from "../chunk-J22F46VT.mjs";
13
+ export {
14
+ CopilotKitAgentDiscoveryError,
15
+ CopilotKitApiDiscoveryError,
16
+ CopilotKitError,
17
+ CopilotKitErrorCode,
18
+ CopilotKitLowLevelError,
19
+ CopilotKitMisuseError,
20
+ CopilotKitRemoteEndpointDiscoveryError,
21
+ ERROR_CONFIG,
22
+ ERROR_NAMES,
23
+ ResolvedCopilotKitError
24
+ };
25
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,6 @@
1
+ export { CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ResolvedCopilotKitError } from './errors.js';
1
2
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema } from './json-schema.js';
2
3
  export { randomId } from './random-id.js';
4
+ import 'graphql';
3
5
  import 'zod';
4
6
  import '../types/action.js';
@@ -20,12 +20,197 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils/index.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
+ CopilotKitAgentDiscoveryError: () => CopilotKitAgentDiscoveryError,
24
+ CopilotKitApiDiscoveryError: () => CopilotKitApiDiscoveryError,
25
+ CopilotKitError: () => CopilotKitError,
26
+ CopilotKitErrorCode: () => CopilotKitErrorCode,
27
+ CopilotKitLowLevelError: () => CopilotKitLowLevelError,
28
+ CopilotKitMisuseError: () => CopilotKitMisuseError,
29
+ CopilotKitRemoteEndpointDiscoveryError: () => CopilotKitRemoteEndpointDiscoveryError,
30
+ ERROR_CONFIG: () => ERROR_CONFIG,
31
+ ERROR_NAMES: () => ERROR_NAMES,
32
+ ResolvedCopilotKitError: () => ResolvedCopilotKitError,
23
33
  actionParametersToJsonSchema: () => actionParametersToJsonSchema,
24
34
  convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
25
35
  randomId: () => randomId
26
36
  });
27
37
  module.exports = __toCommonJS(utils_exports);
28
38
 
39
+ // src/utils/errors.ts
40
+ var import_graphql = require("graphql");
41
+ var ERROR_NAMES = {
42
+ COPILOT_ERROR: "CopilotError",
43
+ COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
44
+ COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
45
+ COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
46
+ COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
47
+ RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError"
48
+ };
49
+ var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
50
+ CopilotKitErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
51
+ CopilotKitErrorCode2["NOT_FOUND"] = "NOT_FOUND";
52
+ CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
53
+ CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
54
+ CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
55
+ CopilotKitErrorCode2["MISUSE"] = "MISUSE";
56
+ CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
57
+ return CopilotKitErrorCode2;
58
+ })(CopilotKitErrorCode || {});
59
+ var BASE_URL = "https://docs.copilotkit.ai";
60
+ var getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
61
+ var ERROR_CONFIG = {
62
+ ["NETWORK_ERROR" /* NETWORK_ERROR */]: {
63
+ statusCode: 503,
64
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
65
+ },
66
+ ["NOT_FOUND" /* NOT_FOUND */]: {
67
+ statusCode: 404,
68
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
69
+ },
70
+ ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
71
+ statusCode: 500,
72
+ troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`
73
+ },
74
+ ["API_NOT_FOUND" /* API_NOT_FOUND */]: {
75
+ statusCode: 404,
76
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`
77
+ },
78
+ ["REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */]: {
79
+ statusCode: 404,
80
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`
81
+ },
82
+ ["MISUSE" /* MISUSE */]: {
83
+ statusCode: 400,
84
+ troubleshootingUrl: null
85
+ },
86
+ ["UNKNOWN" /* UNKNOWN */]: {
87
+ statusCode: 500
88
+ }
89
+ };
90
+ var CopilotKitError = class extends import_graphql.GraphQLError {
91
+ constructor({
92
+ message = "Unknown error occurred",
93
+ code
94
+ }) {
95
+ const name = ERROR_NAMES.COPILOT_ERROR;
96
+ const { statusCode } = ERROR_CONFIG[code];
97
+ super(message, {
98
+ extensions: {
99
+ name,
100
+ statusCode
101
+ }
102
+ });
103
+ this.code = code;
104
+ this.name = name;
105
+ this.statusCode = statusCode;
106
+ }
107
+ };
108
+ var CopilotKitMisuseError = class extends CopilotKitError {
109
+ constructor({
110
+ message,
111
+ code = "MISUSE" /* MISUSE */
112
+ }) {
113
+ const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
114
+ const finalMessage = docsLink ? `${message}.
115
+
116
+ ${docsLink}` : message;
117
+ super({ message: finalMessage, code });
118
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
119
+ }
120
+ };
121
+ var CopilotKitApiDiscoveryError = class extends CopilotKitError {
122
+ constructor(params = {}) {
123
+ const message = params.message ?? "Failed to find CopilotKit API endpoint";
124
+ const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
125
+ const errorMessage = `${message}.
126
+
127
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
128
+ super({ message: errorMessage, code });
129
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
130
+ }
131
+ };
132
+ var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
133
+ constructor(params) {
134
+ const message = (params == null ? void 0 : params.message) ?? "Failed to find or contact remote endpoint";
135
+ const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
136
+ super({ message, code });
137
+ this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
138
+ }
139
+ };
140
+ var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
141
+ constructor(params) {
142
+ const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
143
+ const baseMessage = "Failed to find agent";
144
+ const configMessage = "Please verify the agent name exists and is properly configured.";
145
+ const finalMessage = (params == null ? void 0 : params.agentName) ? `${baseMessage} '${params.agentName}'. ${configMessage}
146
+
147
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}` : `${baseMessage}. ${configMessage}
148
+
149
+ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
150
+ super({ message: finalMessage || finalMessage, code });
151
+ this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
152
+ }
153
+ };
154
+ var CopilotKitLowLevelError = class extends CopilotKitError {
155
+ constructor({ error, url, message }) {
156
+ let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
157
+ const getMessageByCode = (errorCode) => {
158
+ const troubleshootingLink = ERROR_CONFIG[code].troubleshootingUrl;
159
+ switch (errorCode) {
160
+ case "ECONNREFUSED":
161
+ return `Connection to ${url} was refused. Ensure the server is running and accessible.
162
+
163
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
164
+ case "ENOTFOUND":
165
+ return `The server on ${url} could not be found. Check the URL or your network configuration.
166
+
167
+ ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
168
+ case "ETIMEDOUT":
169
+ return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
170
+
171
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
172
+ default:
173
+ return `Failed to fetch from url ${url}.
174
+
175
+ Possible reasons:
176
+ - -The server might be down or unreachable
177
+ - -There might be a network issue (e.g., DNS failure, connection timeout)
178
+ - -The URL might be incorrect
179
+ - -The server is not running on the specified port
180
+
181
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
182
+ }
183
+ };
184
+ const errorMessage = message ?? getMessageByCode(error.code);
185
+ super({ message: errorMessage, code });
186
+ this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
187
+ }
188
+ };
189
+ var ResolvedCopilotKitError = class extends CopilotKitError {
190
+ constructor({
191
+ status,
192
+ message,
193
+ code,
194
+ isRemoteEndpoint
195
+ }) {
196
+ let resolvedCode = code;
197
+ if (!resolvedCode) {
198
+ switch (status) {
199
+ case 400:
200
+ throw new CopilotKitApiDiscoveryError({ message });
201
+ case 404:
202
+ throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message }) : new CopilotKitApiDiscoveryError({ message });
203
+ default:
204
+ resolvedCode = "UNKNOWN" /* UNKNOWN */;
205
+ super({ message, code: resolvedCode });
206
+ }
207
+ } else {
208
+ super({ message, code: resolvedCode });
209
+ }
210
+ this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
211
+ }
212
+ };
213
+
29
214
  // src/utils/json-schema.ts
30
215
  var import_zod = require("zod");
31
216
  function actionParametersToJsonSchema(actionParameters) {
@@ -140,6 +325,16 @@ function randomId() {
140
325
  }
141
326
  // Annotate the CommonJS export names for ESM import in node:
142
327
  0 && (module.exports = {
328
+ CopilotKitAgentDiscoveryError,
329
+ CopilotKitApiDiscoveryError,
330
+ CopilotKitError,
331
+ CopilotKitErrorCode,
332
+ CopilotKitLowLevelError,
333
+ CopilotKitMisuseError,
334
+ CopilotKitRemoteEndpointDiscoveryError,
335
+ ERROR_CONFIG,
336
+ ERROR_NAMES,
337
+ ResolvedCopilotKitError,
143
338
  actionParametersToJsonSchema,
144
339
  convertJsonSchemaToZodSchema,
145
340
  randomId