@copilotkit/shared 1.5.18-next.1 → 1.5.18-next.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 1.5.18-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - f77a7b9: - fix: use warning when version mismatch is not expected to error out
8
+
9
+ ## 1.5.18-next.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 38d3ac2: - fix: add additional info the our error messages
14
+
3
15
  ## 1.5.18-next.1
4
16
 
5
17
  ## 1.5.18-next.0
@@ -2,7 +2,7 @@
2
2
  import { GraphQLError } from "graphql";
3
3
 
4
4
  // package.json
5
- var version = "1.5.18-next.1";
5
+ var version = "1.5.18-next.3";
6
6
 
7
7
  // src/index.ts
8
8
  var COPILOTKIT_VERSION = version;
@@ -121,6 +121,11 @@ ${docsLink}` : message;
121
121
  this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
122
122
  }
123
123
  };
124
+ var getVersionMismatchErrorMessage = ({
125
+ reactCoreVersion,
126
+ runtimeVersion,
127
+ runtimeClientGqlVersion
128
+ }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
124
129
  var CopilotKitVersionMismatchError = class extends CopilotKitError {
125
130
  constructor({
126
131
  reactCoreVersion,
@@ -128,14 +133,30 @@ var CopilotKitVersionMismatchError = class extends CopilotKitError {
128
133
  runtimeClientGqlVersion
129
134
  }) {
130
135
  const code = "VERSION_MISMATCH" /* VERSION_MISMATCH */;
131
- const message = `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
132
- super({ message, code });
136
+ super({
137
+ message: getVersionMismatchErrorMessage({
138
+ reactCoreVersion,
139
+ runtimeVersion,
140
+ runtimeClientGqlVersion
141
+ }),
142
+ code
143
+ });
133
144
  this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
134
145
  }
135
146
  };
136
147
  var CopilotKitApiDiscoveryError = class extends CopilotKitError {
137
148
  constructor(params = {}) {
138
- const message = params.message ?? "Failed to find CopilotKit API endpoint";
149
+ const url = params.url ?? "";
150
+ let operationSuffix = "";
151
+ if (url == null ? void 0 : url.includes("/info"))
152
+ operationSuffix = `when fetching CopilotKit info`;
153
+ else if (url.includes("/actions/execute"))
154
+ operationSuffix = `when attempting to execute actions.`;
155
+ else if (url.includes("/agents/state"))
156
+ operationSuffix = `when attempting to get agent state.`;
157
+ else if (url.includes("/agents/execute"))
158
+ operationSuffix = `when attempting to execute agent(s).`;
159
+ const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
139
160
  const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
140
161
  const errorMessage = `${message}.
141
162
 
@@ -146,7 +167,7 @@ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
146
167
  };
147
168
  var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
148
169
  constructor(params) {
149
- const message = (params == null ? void 0 : params.message) ?? "Failed to find or contact remote endpoint";
170
+ const message = (params == null ? void 0 : params.message) ?? ((params == null ? void 0 : params.url) ? `Failed to find or contact remote endpoint at url ${params.url}` : "Failed to find or contact remote endpoint");
150
171
  const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
151
172
  super({ message, code });
152
173
  this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
@@ -169,34 +190,7 @@ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
169
190
  var CopilotKitLowLevelError = class extends CopilotKitError {
170
191
  constructor({ error, url, message }) {
171
192
  let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
172
- const getMessageByCode = (errorCode) => {
173
- const troubleshootingLink = ERROR_CONFIG[code].troubleshootingUrl;
174
- switch (errorCode) {
175
- case "ECONNREFUSED":
176
- return `Connection to ${url} was refused. Ensure the server is running and accessible.
177
-
178
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
179
- case "ENOTFOUND":
180
- return `The server on ${url} could not be found. Check the URL or your network configuration.
181
-
182
- ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
183
- case "ETIMEDOUT":
184
- return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
185
-
186
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
187
- default:
188
- return `Failed to fetch from url ${url}.
189
-
190
- Possible reasons:
191
- - -The server might be down or unreachable
192
- - -There might be a network issue (e.g., DNS failure, connection timeout)
193
- - -The URL might be incorrect
194
- - -The server is not running on the specified port
195
-
196
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
197
- }
198
- };
199
- const errorMessage = message ?? getMessageByCode(error.code);
193
+ const errorMessage = message ?? resolveLowLevelErrorMessage(error.code);
200
194
  super({ message: errorMessage, code });
201
195
  this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
202
196
  }
@@ -206,15 +200,16 @@ var ResolvedCopilotKitError = class extends CopilotKitError {
206
200
  status,
207
201
  message,
208
202
  code,
209
- isRemoteEndpoint
203
+ isRemoteEndpoint,
204
+ url
210
205
  }) {
211
206
  let resolvedCode = code;
212
207
  if (!resolvedCode) {
213
208
  switch (status) {
214
209
  case 400:
215
- throw new CopilotKitApiDiscoveryError({ message });
210
+ throw new CopilotKitApiDiscoveryError({ message, url });
216
211
  case 404:
217
- throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message }) : new CopilotKitApiDiscoveryError({ message });
212
+ throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
218
213
  default:
219
214
  resolvedCode = "UNKNOWN" /* UNKNOWN */;
220
215
  super({ message, code: resolvedCode });
@@ -246,20 +241,63 @@ var UpgradeRequiredError = class extends ConfigurationError {
246
241
  this.severity = "error" /* Error */;
247
242
  }
248
243
  };
249
- async function detectPossibleVersionMismatchError({
244
+ async function getPossibleVersionMismatch({
250
245
  runtimeVersion,
251
246
  runtimeClientGqlVersion
252
247
  }) {
253
248
  if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
254
249
  return;
255
250
  if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) {
256
- throw new CopilotKitVersionMismatchError({
251
+ return {
257
252
  runtimeVersion,
258
253
  runtimeClientGqlVersion,
259
- reactCoreVersion: COPILOTKIT_VERSION
260
- });
254
+ reactCoreVersion: COPILOTKIT_VERSION,
255
+ message: getVersionMismatchErrorMessage({
256
+ runtimeVersion,
257
+ runtimeClientGqlVersion,
258
+ reactCoreVersion: COPILOTKIT_VERSION
259
+ })
260
+ };
261
261
  }
262
+ return;
262
263
  }
264
+ var resolveLowLevelErrorMessage = ({ errorCode, url }) => {
265
+ const troubleshootingLink = ERROR_CONFIG["NETWORK_ERROR" /* NETWORK_ERROR */].troubleshootingUrl;
266
+ const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
267
+
268
+ Possible reasons:
269
+ - -The server may have an error preventing it from returning a response (Check the server logs for more info).
270
+ - -The server might be down or unreachable
271
+ - -There might be a network issue (e.g., DNS failure, connection timeout)
272
+ - -The URL might be incorrect
273
+ - -The server is not running on the specified port
274
+
275
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
276
+ if (url.includes("/info"))
277
+ return genericMessage(`Failed to fetch CopilotKit agents/action information from url ${url}.`);
278
+ if (url.includes("/actions/execute"))
279
+ return genericMessage(`Fetch call to ${url} to execute actions failed.`);
280
+ if (url.includes("/agents/state"))
281
+ return genericMessage(`Fetch call to ${url} to get agent state failed.`);
282
+ if (url.includes("/agents/execute"))
283
+ return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
284
+ switch (errorCode) {
285
+ case "ECONNREFUSED":
286
+ return `Connection to ${url} was refused. Ensure the server is running and accessible.
287
+
288
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
289
+ case "ENOTFOUND":
290
+ return `The server on ${url} could not be found. Check the URL or your network configuration.
291
+
292
+ ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
293
+ case "ETIMEDOUT":
294
+ return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
295
+
296
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
297
+ default:
298
+ return;
299
+ }
300
+ };
263
301
 
264
302
  export {
265
303
  Severity,
@@ -277,7 +315,7 @@ export {
277
315
  ConfigurationError,
278
316
  MissingPublicApiKeyError,
279
317
  UpgradeRequiredError,
280
- detectPossibleVersionMismatchError,
318
+ getPossibleVersionMismatch,
281
319
  COPILOTKIT_VERSION
282
320
  };
283
- //# sourceMappingURL=chunk-R54GFGOM.mjs.map
321
+ //# sourceMappingURL=chunk-OSR2X6PY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/errors.ts","../package.json","../src/index.ts"],"sourcesContent":["import { GraphQLError } from \"graphql\";\nimport { COPILOTKIT_VERSION } from \"../index\";\n\nexport enum Severity {\n Error = \"error\",\n}\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 COPILOT_KIT_VERSION_MISMATCH_ERROR: \"CopilotKitVersionMismatchError\",\n RESOLVED_COPILOT_KIT_ERROR: \"ResolvedCopilotKitError\",\n CONFIGURATION_ERROR: \"ConfigurationError\",\n MISSING_PUBLIC_API_KEY_ERROR: \"MissingPublicApiKeyError\",\n UPGRADE_REQUIRED_ERROR: \"UpgradeRequiredError\",\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 VERSION_MISMATCH = \"VERSION_MISMATCH\",\n CONFIGURATION_ERROR = \"CONFIGURATION_ERROR\",\n MISSING_PUBLIC_API_KEY_ERROR = \"MISSING_PUBLIC_API_KEY_ERROR\",\n UPGRADE_REQUIRED_ERROR = \"UPGRADE_REQUIRED_ERROR\",\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 [CopilotKitErrorCode.CONFIGURATION_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.Error,\n },\n [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.Error,\n },\n [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {\n statusCode: 402,\n troubleshootingUrl: null,\n severity: Severity.Error,\n },\n [CopilotKitErrorCode.VERSION_MISMATCH]: {\n statusCode: 400,\n troubleshootingUrl: null,\n },\n};\n\nexport class CopilotKitError extends GraphQLError {\n code: CopilotKitErrorCode;\n statusCode: number;\n severity?: Severity;\n constructor({\n message = \"Unknown error occurred\",\n code,\n severity,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n severity?: Severity;\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 this.severity = severity;\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\nconst getVersionMismatchErrorMessage = ({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n}: VersionMismatchResponse) =>\n `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? \"\"} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;\n/**\n * Error thrown when CPK versions does not match\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitVersionMismatchError extends CopilotKitError {\n constructor({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }: VersionMismatchResponse) {\n const code = CopilotKitErrorCode.VERSION_MISMATCH;\n super({\n message: getVersionMismatchErrorMessage({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }),\n code,\n });\n this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_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 url?: string;\n } = {},\n ) {\n const url = params.url ?? \"\";\n let operationSuffix = \"\";\n if (url?.includes(\"/info\")) operationSuffix = `when fetching CopilotKit info`;\n else if (url.includes(\"/actions/execute\"))\n operationSuffix = `when attempting to execute actions.`;\n else if (url.includes(\"/agents/state\")) operationSuffix = `when attempting to get agent state.`;\n else if (url.includes(\"/agents/execute\"))\n operationSuffix = `when attempting to execute agent(s).`;\n const message =\n params.message ??\n (params.url\n ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}`\n : `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; url?: string }) {\n const message =\n params?.message ??\n (params?.url\n ? `Failed to find or contact remote endpoint at url ${params.url}`\n : \"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 // @ts-expect-error -- code may exist\n const errorMessage = message ?? resolveLowLevelErrorMessage(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 url,\n }: {\n status: number;\n message?: string;\n code?: CopilotKitErrorCode;\n isRemoteEndpoint?: boolean;\n url?: string;\n }) {\n let resolvedCode = code;\n if (!resolvedCode) {\n switch (status) {\n case 400:\n throw new CopilotKitApiDiscoveryError({ message, url });\n case 404:\n throw isRemoteEndpoint\n ? new CopilotKitRemoteEndpointDiscoveryError({ message, url })\n : new CopilotKitApiDiscoveryError({ message, url });\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\nexport class ConfigurationError extends CopilotKitError {\n constructor(message: string) {\n super({ message, code: CopilotKitErrorCode.CONFIGURATION_ERROR });\n this.name = ERROR_NAMES.CONFIGURATION_ERROR;\n this.severity = Severity.Error;\n }\n}\n\nexport class MissingPublicApiKeyError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;\n this.severity = Severity.Error;\n }\n}\n\nexport class UpgradeRequiredError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;\n this.severity = Severity.Error;\n }\n}\n\ninterface VersionMismatchResponse {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n reactCoreVersion: string;\n}\n\nexport async function getPossibleVersionMismatch({\n runtimeVersion,\n runtimeClientGqlVersion,\n}: {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n}) {\n if (!runtimeVersion || runtimeVersion === \"\" || !runtimeClientGqlVersion) return;\n if (\n COPILOTKIT_VERSION !== runtimeVersion ||\n COPILOTKIT_VERSION !== runtimeClientGqlVersion ||\n runtimeVersion !== runtimeClientGqlVersion\n ) {\n return {\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n message: getVersionMismatchErrorMessage({\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n }),\n };\n }\n\n return;\n}\n\nconst resolveLowLevelErrorMessage = ({ errorCode, url }: { errorCode?: string; url: string }) => {\n const troubleshootingLink = ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;\n const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.\n\nPossible reasons:\n- -The server may have an error preventing it from returning a response (Check the server logs for more info).\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 if (url.includes(\"/info\"))\n return genericMessage(`Failed to fetch CopilotKit agents/action information from url ${url}.`);\n if (url.includes(\"/actions/execute\"))\n return genericMessage(`Fetch call to ${url} to execute actions failed.`);\n if (url.includes(\"/agents/state\"))\n return genericMessage(`Fetch call to ${url} to get agent state failed.`);\n if (url.includes(\"/agents/execute\"))\n return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);\n\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;\n }\n};\n","{\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.18-next.3\",\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":";AAAA,SAAS,oBAAoB;;;ACW3B,cAAW;;;ACLN,IAAM,qBAAiC;;;AFHvC,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,WAAQ;AADE,SAAAA;AAAA,GAAA;AAIL,IAAM,cAAc;AAAA,EACzB,eAAe;AAAA,EACf,6BAA6B;AAAA,EAC7B,yCAAyC;AAAA,EACzC,mCAAmC;AAAA,EACnC,6BAA6B;AAAA,EAC7B,oCAAoC;AAAA,EACpC,4BAA4B;AAAA,EAC5B,qBAAqB;AAAA,EACr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ClB;AACF;AAQA,eAAsB,2BAA2B;AAAA,EAC/C;AAAA,EACA;AACF,GAGG;AACD,MAAI,CAAC,kBAAkB,mBAAmB,MAAM,CAAC;AAAyB;AAC1E,MACE,uBAAuB,kBACvB,uBAAuB,2BACvB,mBAAmB,yBACnB;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,SAAS,+BAA+B;AAAA,QACtC;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,MACpB,CAAC;AAAA,IACH;AAAA,EACF;AAEA;AACF;AAEA,IAAM,8BAA8B,CAAC,EAAE,WAAW,IAAI,MAA2C;AAC/F,QAAM,sBAAsB,aAAa,mCAAiC,EAAE;AAC5E,QAAM,iBAAiB,CAAC,cAAc,4BAA4B,WAAW,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAShF,mBAAmB,mBAAmB;AAEtC,MAAI,IAAI,SAAS,OAAO;AACtB,WAAO,eAAe,iEAAiE,MAAM;AAC/F,MAAI,IAAI,SAAS,kBAAkB;AACjC,WAAO,eAAe,iBAAiB,gCAAgC;AACzE,MAAI,IAAI,SAAS,eAAe;AAC9B,WAAO,eAAe,iBAAiB,gCAAgC;AACzE,MAAI,IAAI,SAAS,iBAAiB;AAChC,WAAO,eAAe,iBAAiB,iCAAiC;AAE1E,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO,iBAAiB;AAAA;AAAA,EAAoE,mBAAmB,mBAAmB;AAAA,IACpI,KAAK;AACH,aAAO,iBAAiB;AAAA;AAAA,EAA2E,mBAAmB,aAAa,2BAA6B,EAAE,kBAAkB;AAAA,IACtL,KAAK;AACH,aAAO,qBAAqB;AAAA;AAAA,EAAmF,mBAAmB,mBAAmB;AAAA,IACvJ;AACE;AAAA,EACJ;AACF;","names":["Severity","CopilotKitErrorCode"]}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { Action, MappedParameterTypes, Parameter } from './types/action.js';
3
3
  export { CopilotCloudConfig } from './types/copilot-cloud-config.js';
4
4
  export { PartialBy, RequiredBy } from './types/utility.js';
5
5
  export { BaseCondition, ComparisonCondition, ComparisonRule, Condition, ExistenceCondition, ExistenceRule, LogicalCondition, LogicalRule, Rule, executeConditions } from './utils/conditions.js';
6
- export { ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, detectPossibleVersionMismatchError } from './utils/errors.js';
6
+ export { ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, getPossibleVersionMismatch } from './utils/errors.js';
7
7
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema } from './utils/json-schema.js';
8
8
  export { dataToUUID, isValidUUID, randomId, randomUUID } from './utils/random-id.js';
9
9
  export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
package/dist/index.js CHANGED
@@ -54,8 +54,8 @@ __export(src_exports, {
54
54
  actionParametersToJsonSchema: () => actionParametersToJsonSchema,
55
55
  convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
56
56
  dataToUUID: () => dataToUUID,
57
- detectPossibleVersionMismatchError: () => detectPossibleVersionMismatchError,
58
57
  executeConditions: () => executeConditions,
58
+ getPossibleVersionMismatch: () => getPossibleVersionMismatch,
59
59
  isValidUUID: () => isValidUUID,
60
60
  randomId: () => randomId,
61
61
  randomUUID: () => randomUUID
@@ -223,6 +223,11 @@ ${docsLink}` : message;
223
223
  this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
224
224
  }
225
225
  };
226
+ var getVersionMismatchErrorMessage = ({
227
+ reactCoreVersion,
228
+ runtimeVersion,
229
+ runtimeClientGqlVersion
230
+ }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
226
231
  var CopilotKitVersionMismatchError = class extends CopilotKitError {
227
232
  constructor({
228
233
  reactCoreVersion,
@@ -230,14 +235,30 @@ var CopilotKitVersionMismatchError = class extends CopilotKitError {
230
235
  runtimeClientGqlVersion
231
236
  }) {
232
237
  const code = "VERSION_MISMATCH" /* VERSION_MISMATCH */;
233
- const message = `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
234
- super({ message, code });
238
+ super({
239
+ message: getVersionMismatchErrorMessage({
240
+ reactCoreVersion,
241
+ runtimeVersion,
242
+ runtimeClientGqlVersion
243
+ }),
244
+ code
245
+ });
235
246
  this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
236
247
  }
237
248
  };
238
249
  var CopilotKitApiDiscoveryError = class extends CopilotKitError {
239
250
  constructor(params = {}) {
240
- const message = params.message ?? "Failed to find CopilotKit API endpoint";
251
+ const url = params.url ?? "";
252
+ let operationSuffix = "";
253
+ if (url == null ? void 0 : url.includes("/info"))
254
+ operationSuffix = `when fetching CopilotKit info`;
255
+ else if (url.includes("/actions/execute"))
256
+ operationSuffix = `when attempting to execute actions.`;
257
+ else if (url.includes("/agents/state"))
258
+ operationSuffix = `when attempting to get agent state.`;
259
+ else if (url.includes("/agents/execute"))
260
+ operationSuffix = `when attempting to execute agent(s).`;
261
+ const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
241
262
  const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
242
263
  const errorMessage = `${message}.
243
264
 
@@ -248,7 +269,7 @@ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
248
269
  };
249
270
  var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
250
271
  constructor(params) {
251
- const message = (params == null ? void 0 : params.message) ?? "Failed to find or contact remote endpoint";
272
+ const message = (params == null ? void 0 : params.message) ?? ((params == null ? void 0 : params.url) ? `Failed to find or contact remote endpoint at url ${params.url}` : "Failed to find or contact remote endpoint");
252
273
  const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
253
274
  super({ message, code });
254
275
  this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
@@ -271,34 +292,7 @@ ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
271
292
  var CopilotKitLowLevelError = class extends CopilotKitError {
272
293
  constructor({ error, url, message }) {
273
294
  let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
274
- const getMessageByCode = (errorCode) => {
275
- const troubleshootingLink = ERROR_CONFIG[code].troubleshootingUrl;
276
- switch (errorCode) {
277
- case "ECONNREFUSED":
278
- return `Connection to ${url} was refused. Ensure the server is running and accessible.
279
-
280
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
281
- case "ENOTFOUND":
282
- return `The server on ${url} could not be found. Check the URL or your network configuration.
283
-
284
- ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
285
- case "ETIMEDOUT":
286
- return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
287
-
288
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
289
- default:
290
- return `Failed to fetch from url ${url}.
291
-
292
- Possible reasons:
293
- - -The server might be down or unreachable
294
- - -There might be a network issue (e.g., DNS failure, connection timeout)
295
- - -The URL might be incorrect
296
- - -The server is not running on the specified port
297
-
298
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
299
- }
300
- };
301
- const errorMessage = message ?? getMessageByCode(error.code);
295
+ const errorMessage = message ?? resolveLowLevelErrorMessage(error.code);
302
296
  super({ message: errorMessage, code });
303
297
  this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
304
298
  }
@@ -308,15 +302,16 @@ var ResolvedCopilotKitError = class extends CopilotKitError {
308
302
  status,
309
303
  message,
310
304
  code,
311
- isRemoteEndpoint
305
+ isRemoteEndpoint,
306
+ url
312
307
  }) {
313
308
  let resolvedCode = code;
314
309
  if (!resolvedCode) {
315
310
  switch (status) {
316
311
  case 400:
317
- throw new CopilotKitApiDiscoveryError({ message });
312
+ throw new CopilotKitApiDiscoveryError({ message, url });
318
313
  case 404:
319
- throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message }) : new CopilotKitApiDiscoveryError({ message });
314
+ throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
320
315
  default:
321
316
  resolvedCode = "UNKNOWN" /* UNKNOWN */;
322
317
  super({ message, code: resolvedCode });
@@ -348,20 +343,63 @@ var UpgradeRequiredError = class extends ConfigurationError {
348
343
  this.severity = "error" /* Error */;
349
344
  }
350
345
  };
351
- async function detectPossibleVersionMismatchError({
346
+ async function getPossibleVersionMismatch({
352
347
  runtimeVersion,
353
348
  runtimeClientGqlVersion
354
349
  }) {
355
350
  if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
356
351
  return;
357
352
  if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) {
358
- throw new CopilotKitVersionMismatchError({
353
+ return {
359
354
  runtimeVersion,
360
355
  runtimeClientGqlVersion,
361
- reactCoreVersion: COPILOTKIT_VERSION
362
- });
356
+ reactCoreVersion: COPILOTKIT_VERSION,
357
+ message: getVersionMismatchErrorMessage({
358
+ runtimeVersion,
359
+ runtimeClientGqlVersion,
360
+ reactCoreVersion: COPILOTKIT_VERSION
361
+ })
362
+ };
363
363
  }
364
+ return;
364
365
  }
366
+ var resolveLowLevelErrorMessage = ({ errorCode, url }) => {
367
+ const troubleshootingLink = ERROR_CONFIG["NETWORK_ERROR" /* NETWORK_ERROR */].troubleshootingUrl;
368
+ const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
369
+
370
+ Possible reasons:
371
+ - -The server may have an error preventing it from returning a response (Check the server logs for more info).
372
+ - -The server might be down or unreachable
373
+ - -There might be a network issue (e.g., DNS failure, connection timeout)
374
+ - -The URL might be incorrect
375
+ - -The server is not running on the specified port
376
+
377
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
378
+ if (url.includes("/info"))
379
+ return genericMessage(`Failed to fetch CopilotKit agents/action information from url ${url}.`);
380
+ if (url.includes("/actions/execute"))
381
+ return genericMessage(`Fetch call to ${url} to execute actions failed.`);
382
+ if (url.includes("/agents/state"))
383
+ return genericMessage(`Fetch call to ${url} to get agent state failed.`);
384
+ if (url.includes("/agents/execute"))
385
+ return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
386
+ switch (errorCode) {
387
+ case "ECONNREFUSED":
388
+ return `Connection to ${url} was refused. Ensure the server is running and accessible.
389
+
390
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
391
+ case "ENOTFOUND":
392
+ return `The server on ${url} could not be found. Check the URL or your network configuration.
393
+
394
+ ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
395
+ case "ETIMEDOUT":
396
+ return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
397
+
398
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
399
+ default:
400
+ return;
401
+ }
402
+ };
365
403
 
366
404
  // src/utils/json-schema.ts
367
405
  var import_zod = require("zod");
@@ -598,7 +636,7 @@ var TelemetryClient = class {
598
636
  };
599
637
 
600
638
  // package.json
601
- var version = "1.5.18-next.1";
639
+ var version = "1.5.18-next.3";
602
640
 
603
641
  // src/index.ts
604
642
  var COPILOTKIT_VERSION = version;
@@ -628,8 +666,8 @@ var COPILOTKIT_VERSION = version;
628
666
  actionParametersToJsonSchema,
629
667
  convertJsonSchemaToZodSchema,
630
668
  dataToUUID,
631
- detectPossibleVersionMismatchError,
632
669
  executeConditions,
670
+ getPossibleVersionMismatch,
633
671
  isValidUUID,
634
672
  randomId,
635
673
  randomUUID