@copilotkit/shared 1.9.2-next.8 → 1.9.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 CHANGED
@@ -1,5 +1,65 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 1.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - fac89c2: - refactor: rename onTrace to onError throughout codebase
8
+
9
+ - Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
10
+
11
+ - 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
12
+ - 1d1c51d: - feat: surface all errors in structured format
13
+ - 10345a5: - feat: structured error visibility system for streaming errors
14
+ - 9169ad7: - feat: add onTrace handler for comprehensive debugging and observability - Add CopilotTraceEvent interfaces with rich debugging context, implement runtime-side tracing with publicApiKey gating, add UI-side error tracing, include comprehensive test coverage, and fix tsup build config to exclude test files
15
+ - fix: extract publicApiKey for all requests + trace GraphQL errors
16
+
17
+ ## 1.9.2-next.26
18
+
19
+ ## 1.9.2-next.25
20
+
21
+ ## 1.9.2-next.24
22
+
23
+ ## 1.9.2-next.23
24
+
25
+ ## 1.9.2-next.22
26
+
27
+ ## 1.9.2-next.21
28
+
29
+ ## 1.9.2-next.20
30
+
31
+ ## 1.9.2-next.19
32
+
33
+ ## 1.9.2-next.18
34
+
35
+ ### Patch Changes
36
+
37
+ - fac89c2: - refactor: rename onTrace to onError throughout codebase
38
+
39
+ - Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
40
+
41
+ ## 1.9.2-next.17
42
+
43
+ ## 1.9.2-next.16
44
+
45
+ ## 1.9.2-next.15
46
+
47
+ ## 1.9.2-next.14
48
+
49
+ ## 1.9.2-next.13
50
+
51
+ ## 1.9.2-next.12
52
+
53
+ ## 1.9.2-next.11
54
+
55
+ ## 1.9.2-next.10
56
+
57
+ ## 1.9.2-next.9
58
+
59
+ ### Patch Changes
60
+
61
+ - 1d1c51d: - feat: surface all errors in structured format
62
+
3
63
  ## 1.9.2-next.8
4
64
 
5
65
  ## 1.9.2-next.7
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-2OJ5OJ2D.mjs.map
@@ -24,7 +24,7 @@ function isMacOS() {
24
24
  }
25
25
 
26
26
  // package.json
27
- var version = "1.9.2-next.8";
27
+ var version = "1.9.2";
28
28
 
29
29
  // src/index.ts
30
30
  var COPILOTKIT_VERSION = version;
@@ -70,6 +70,7 @@ var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
70
70
  CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
71
71
  CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
72
72
  CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
73
+ CopilotKitErrorCode2["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
73
74
  CopilotKitErrorCode2["MISUSE"] = "MISUSE";
74
75
  CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
75
76
  CopilotKitErrorCode2["VERSION_MISMATCH"] = "VERSION_MISMATCH";
@@ -84,14 +85,14 @@ var ERROR_CONFIG = {
84
85
  ["NETWORK_ERROR" /* NETWORK_ERROR */]: {
85
86
  statusCode: 503,
86
87
  troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
87
- visibility: "toast" /* TOAST */,
88
- severity: "info" /* INFO */
88
+ visibility: "banner" /* BANNER */,
89
+ severity: "critical" /* CRITICAL */
89
90
  },
90
91
  ["NOT_FOUND" /* NOT_FOUND */]: {
91
92
  statusCode: 404,
92
93
  troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
93
- visibility: "toast" /* TOAST */,
94
- severity: "info" /* INFO */
94
+ visibility: "banner" /* BANNER */,
95
+ severity: "critical" /* CRITICAL */
95
96
  },
96
97
  ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
97
98
  statusCode: 500,
@@ -111,6 +112,12 @@ var ERROR_CONFIG = {
111
112
  visibility: "banner" /* BANNER */,
112
113
  severity: "critical" /* CRITICAL */
113
114
  },
115
+ ["AUTHENTICATION_ERROR" /* AUTHENTICATION_ERROR */]: {
116
+ statusCode: 401,
117
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
118
+ visibility: "banner" /* BANNER */,
119
+ severity: "critical" /* CRITICAL */
120
+ },
114
121
  ["MISUSE" /* MISUSE */]: {
115
122
  statusCode: 400,
116
123
  troubleshootingUrl: null,
@@ -120,7 +127,7 @@ var ERROR_CONFIG = {
120
127
  ["UNKNOWN" /* UNKNOWN */]: {
121
128
  statusCode: 500,
122
129
  visibility: "toast" /* TOAST */,
123
- severity: "info" /* INFO */
130
+ severity: "critical" /* CRITICAL */
124
131
  },
125
132
  ["CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */]: {
126
133
  statusCode: 400,
@@ -249,23 +256,21 @@ var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
249
256
  constructor(params) {
250
257
  const { agentName, availableAgents } = params;
251
258
  const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
252
- let message = "Failed to find any agents.";
253
- const configMessage = "Please verify the agent name exists and is properly configured.";
254
259
  const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
260
+ let message;
255
261
  if (availableAgents.length) {
256
- message = agentName ? `Failed to find agent '${agentName}'. ${configMessage}` : `Failed to find agent. ${configMessage}`;
257
- const bulletList = availableAgents.map((agent) => `\u2022 ${agent.name} (ID: \`${agent.id}\`)`).join("\n");
258
- message += `
259
-
260
- The available agents are:
261
-
262
- ${bulletList}
262
+ const agentList = availableAgents.map((agent) => agent.name).join(", ");
263
+ if (agentName) {
264
+ message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
263
265
 
264
266
  ${seeMore}`;
265
- } else {
266
- message += `
267
+ } else {
268
+ message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
267
269
 
268
270
  ${seeMore}`;
271
+ }
272
+ } else {
273
+ message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
269
274
  }
270
275
  super({ message, code });
271
276
  this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
@@ -297,11 +302,10 @@ var ResolvedCopilotKitError = class extends CopilotKitError {
297
302
  throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
298
303
  default:
299
304
  resolvedCode = "UNKNOWN" /* UNKNOWN */;
300
- super({ message, code: resolvedCode, visibility: "banner" /* BANNER */ });
305
+ break;
301
306
  }
302
- } else {
303
- super({ message, code: resolvedCode });
304
307
  }
308
+ super({ message, code: resolvedCode });
305
309
  this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
306
310
  }
307
311
  };
@@ -326,6 +330,13 @@ var UpgradeRequiredError = class extends ConfigurationError {
326
330
  this.severity = "warning" /* WARNING */;
327
331
  }
328
332
  };
333
+ function isStructuredCopilotKitError(error) {
334
+ var _a;
335
+ return error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError || (error == null ? void 0 : error.name) && error.name.includes("CopilotKit") || ((_a = error == null ? void 0 : error.extensions) == null ? void 0 : _a.code) !== void 0;
336
+ }
337
+ function ensureStructuredError(error, converter) {
338
+ return isStructuredCopilotKitError(error) ? error : converter(error);
339
+ }
329
340
  async function getPossibleVersionMismatch({
330
341
  runtimeVersion,
331
342
  runtimeClientGqlVersion
@@ -403,10 +414,12 @@ export {
403
414
  ConfigurationError,
404
415
  MissingPublicApiKeyError,
405
416
  UpgradeRequiredError,
417
+ isStructuredCopilotKitError,
418
+ ensureStructuredError,
406
419
  getPossibleVersionMismatch,
407
420
  parseJson,
408
421
  tryMap,
409
422
  isMacOS,
410
423
  COPILOTKIT_VERSION
411
424
  };
412
- //# sourceMappingURL=chunk-VCC7YVX5.mjs.map
425
+ //# sourceMappingURL=chunk-PH5XSDMB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/errors.ts","../src/utils/index.ts","../package.json","../src/index.ts"],"sourcesContent":["import { GraphQLError } from \"graphql\";\nimport { COPILOTKIT_VERSION } from \"../index\";\n\nexport enum Severity {\n CRITICAL = \"critical\", // Critical errors that block core functionality\n WARNING = \"warning\", // Configuration/setup issues that need attention\n INFO = \"info\", // General errors and network issues\n}\n\nexport enum ErrorVisibility {\n BANNER = \"banner\", // Critical errors shown as fixed banners\n TOAST = \"toast\", // Regular errors shown as dismissible toasts\n SILENT = \"silent\", // Errors logged but not shown to user\n DEV_ONLY = \"dev_only\", // Errors only shown in development mode\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\n// Banner errors - critical configuration/discovery issues\nexport const BANNER_ERROR_NAMES = [\n ERROR_NAMES.CONFIGURATION_ERROR,\n ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,\n ERROR_NAMES.UPGRADE_REQUIRED_ERROR,\n ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR,\n];\n\n// Legacy cloud error names for backward compatibility\nexport const COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;\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 AUTHENTICATION_ERROR = \"AUTHENTICATION_ERROR\",\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 visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\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 visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\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 visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\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 visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\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 visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AUTHENTICATION_ERROR]: {\n statusCode: 401,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.MISUSE]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.WARNING,\n },\n [CopilotKitErrorCode.UNKNOWN]: {\n statusCode: 500,\n visibility: ErrorVisibility.TOAST,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.CONFIGURATION_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {\n statusCode: 402,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.VERSION_MISMATCH]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.INFO,\n },\n};\n\nexport class CopilotKitError extends GraphQLError {\n code: CopilotKitErrorCode;\n statusCode: number;\n severity?: Severity;\n visibility: ErrorVisibility;\n\n constructor({\n message = \"Unknown error occurred\",\n code,\n severity,\n visibility,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n severity?: Severity;\n visibility?: ErrorVisibility;\n }) {\n const name = ERROR_NAMES.COPILOT_ERROR;\n const config = ERROR_CONFIG[code];\n const { statusCode } = config;\n const resolvedVisibility = visibility ?? config.visibility ?? ErrorVisibility.TOAST;\n const resolvedSeverity = severity ?? (\"severity\" in config ? config.severity : undefined);\n\n super(message, {\n extensions: {\n name,\n statusCode,\n code,\n visibility: resolvedVisibility,\n severity: resolvedSeverity,\n troubleshootingUrl: \"troubleshootingUrl\" in config ? config.troubleshootingUrl : null,\n originalError: {\n message,\n stack: new Error().stack,\n },\n },\n });\n\n this.code = code;\n this.name = name;\n this.statusCode = statusCode;\n this.severity = resolvedSeverity;\n this.visibility = resolvedVisibility;\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] && ERROR_CONFIG[code].troubleshootingUrl\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; availableAgents: { name: string; id: string }[] }) {\n const { agentName, availableAgents } = params;\n const code = CopilotKitErrorCode.AGENT_NOT_FOUND;\n\n const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);\n let message;\n\n if (availableAgents.length) {\n const agentList = availableAgents.map((agent) => agent.name).join(\", \");\n\n if (agentName) {\n message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n } else {\n message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n }\n } else {\n message = `${agentName ? `Agent '${agentName}'` : \"The requested agent\"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;\n }\n\n super({ message, 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 errorCode = error.code as string;\n const errorMessage = message ?? resolveLowLevelErrorMessage({ errorCode, url });\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 break;\n }\n }\n\n super({ message, code: resolvedCode });\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.WARNING;\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.CRITICAL;\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.WARNING;\n }\n}\n\n/**\n * Checks if an error is already a structured CopilotKit error.\n * This utility centralizes the logic for detecting structured errors across the codebase.\n *\n * @param error - The error to check\n * @returns true if the error is already structured, false otherwise\n */\nexport function isStructuredCopilotKitError(error: any): boolean {\n return (\n error instanceof CopilotKitError ||\n error instanceof CopilotKitLowLevelError ||\n (error?.name && error.name.includes(\"CopilotKit\")) ||\n error?.extensions?.code !== undefined // Check if it has our structured error properties\n );\n}\n\n/**\n * Returns the error as-is if it's already structured, otherwise converts it using the provided converter function.\n * This utility centralizes the pattern of preserving structured errors while converting unstructured ones.\n *\n * @param error - The error to process\n * @param converter - Function to convert unstructured errors to structured ones\n * @returns The structured error\n */\nexport function ensureStructuredError<T extends CopilotKitError>(\n error: any,\n converter: (error: any) => T,\n): T | any {\n return isStructuredCopilotKitError(error) ? error : converter(error);\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","export * from \"./conditions\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./random-id\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\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.9.2\",\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;;;ACWtB,SAAS,UAAU,MAAc,WAAgB,SAAS;AAC/D,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAP;AACA,WAAO,aAAa,UAAU,OAAO;AAAA,EACvC;AACF;AAQO,SAAS,OACd,OACA,UACW;AACX,SAAO,MAAM,OAAkB,CAAC,KAAK,MAAM,OAAO,UAAU;AAC1D,QAAI;AACF,UAAI,KAAK,SAAS,MAAM,OAAO,KAAK,CAAC;AAAA,IACvC,SAAS,OAAP;AACA,cAAQ,MAAM,KAAK;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAMO,SAAS,UAAmB;AACjC,SAAO,sBAAsB,KAAK,UAAU,SAAS;AACvD;;;AClCE,cAAW;;;ACLN,IAAM,qBAAiC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AS,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","ErrorVisibility","CopilotKitErrorCode"]}
package/dist/index.d.ts CHANGED
@@ -2,12 +2,12 @@ export { AssistantMessage, CoAgentStateRenderHandler, CoAgentStateRenderHandlerA
2
2
  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
- export { CopilotRequestContext, CopilotTraceEvent, CopilotTraceHandler } from './types/trace.js';
5
+ export { CopilotErrorEvent, CopilotErrorHandler, CopilotRequestContext } from './types/error.js';
6
6
  export { isMacOS, parseJson, tryMap } from './utils/index.js';
7
7
  export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
8
8
  export { TelemetryClient } from './telemetry/telemetry-client.js';
9
9
  export { BaseCondition, ComparisonCondition, ComparisonRule, Condition, ExistenceCondition, ExistenceRule, LogicalCondition, LogicalRule, Rule, executeConditions } from './utils/conditions.js';
10
- export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, getPossibleVersionMismatch } from './utils/errors.js';
10
+ export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from './utils/errors.js';
11
11
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, jsonSchemaToActionParameters } from './utils/json-schema.js';
12
12
  export { dataToUUID, isValidUUID, randomId, randomUUID } from './utils/random-id.js';
13
13
  import '@segment/analytics-node';
package/dist/index.js CHANGED
@@ -57,9 +57,11 @@ __export(src_exports, {
57
57
  actionParametersToJsonSchema: () => actionParametersToJsonSchema,
58
58
  convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
59
59
  dataToUUID: () => dataToUUID,
60
+ ensureStructuredError: () => ensureStructuredError,
60
61
  executeConditions: () => executeConditions,
61
62
  getPossibleVersionMismatch: () => getPossibleVersionMismatch,
62
63
  isMacOS: () => isMacOS,
64
+ isStructuredCopilotKitError: () => isStructuredCopilotKitError,
63
65
  isValidUUID: () => isValidUUID,
64
66
  jsonSchemaToActionParameters: () => jsonSchemaToActionParameters,
65
67
  parseJson: () => parseJson,
@@ -157,6 +159,7 @@ var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
157
159
  CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
158
160
  CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
159
161
  CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
162
+ CopilotKitErrorCode2["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
160
163
  CopilotKitErrorCode2["MISUSE"] = "MISUSE";
161
164
  CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
162
165
  CopilotKitErrorCode2["VERSION_MISMATCH"] = "VERSION_MISMATCH";
@@ -171,14 +174,14 @@ var ERROR_CONFIG = {
171
174
  ["NETWORK_ERROR" /* NETWORK_ERROR */]: {
172
175
  statusCode: 503,
173
176
  troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
174
- visibility: "toast" /* TOAST */,
175
- severity: "info" /* INFO */
177
+ visibility: "banner" /* BANNER */,
178
+ severity: "critical" /* CRITICAL */
176
179
  },
177
180
  ["NOT_FOUND" /* NOT_FOUND */]: {
178
181
  statusCode: 404,
179
182
  troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
180
- visibility: "toast" /* TOAST */,
181
- severity: "info" /* INFO */
183
+ visibility: "banner" /* BANNER */,
184
+ severity: "critical" /* CRITICAL */
182
185
  },
183
186
  ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
184
187
  statusCode: 500,
@@ -198,6 +201,12 @@ var ERROR_CONFIG = {
198
201
  visibility: "banner" /* BANNER */,
199
202
  severity: "critical" /* CRITICAL */
200
203
  },
204
+ ["AUTHENTICATION_ERROR" /* AUTHENTICATION_ERROR */]: {
205
+ statusCode: 401,
206
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
207
+ visibility: "banner" /* BANNER */,
208
+ severity: "critical" /* CRITICAL */
209
+ },
201
210
  ["MISUSE" /* MISUSE */]: {
202
211
  statusCode: 400,
203
212
  troubleshootingUrl: null,
@@ -207,7 +216,7 @@ var ERROR_CONFIG = {
207
216
  ["UNKNOWN" /* UNKNOWN */]: {
208
217
  statusCode: 500,
209
218
  visibility: "toast" /* TOAST */,
210
- severity: "info" /* INFO */
219
+ severity: "critical" /* CRITICAL */
211
220
  },
212
221
  ["CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */]: {
213
222
  statusCode: 400,
@@ -336,23 +345,21 @@ var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
336
345
  constructor(params) {
337
346
  const { agentName, availableAgents } = params;
338
347
  const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
339
- let message = "Failed to find any agents.";
340
- const configMessage = "Please verify the agent name exists and is properly configured.";
341
348
  const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
349
+ let message;
342
350
  if (availableAgents.length) {
343
- message = agentName ? `Failed to find agent '${agentName}'. ${configMessage}` : `Failed to find agent. ${configMessage}`;
344
- const bulletList = availableAgents.map((agent) => `\u2022 ${agent.name} (ID: \`${agent.id}\`)`).join("\n");
345
- message += `
346
-
347
- The available agents are:
348
-
349
- ${bulletList}
351
+ const agentList = availableAgents.map((agent) => agent.name).join(", ");
352
+ if (agentName) {
353
+ message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
350
354
 
351
355
  ${seeMore}`;
352
- } else {
353
- message += `
356
+ } else {
357
+ message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
354
358
 
355
359
  ${seeMore}`;
360
+ }
361
+ } else {
362
+ message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
356
363
  }
357
364
  super({ message, code });
358
365
  this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
@@ -384,11 +391,10 @@ var ResolvedCopilotKitError = class extends CopilotKitError {
384
391
  throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
385
392
  default:
386
393
  resolvedCode = "UNKNOWN" /* UNKNOWN */;
387
- super({ message, code: resolvedCode, visibility: "banner" /* BANNER */ });
394
+ break;
388
395
  }
389
- } else {
390
- super({ message, code: resolvedCode });
391
396
  }
397
+ super({ message, code: resolvedCode });
392
398
  this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
393
399
  }
394
400
  };
@@ -413,6 +419,13 @@ var UpgradeRequiredError = class extends ConfigurationError {
413
419
  this.severity = "warning" /* WARNING */;
414
420
  }
415
421
  };
422
+ function isStructuredCopilotKitError(error) {
423
+ var _a;
424
+ return error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError || (error == null ? void 0 : error.name) && error.name.includes("CopilotKit") || ((_a = error == null ? void 0 : error.extensions) == null ? void 0 : _a.code) !== void 0;
425
+ }
426
+ function ensureStructuredError(error, converter) {
427
+ return isStructuredCopilotKitError(error) ? error : converter(error);
428
+ }
416
429
  async function getPossibleVersionMismatch({
417
430
  runtimeVersion,
418
431
  runtimeClientGqlVersion
@@ -810,7 +823,7 @@ var TelemetryClient = class {
810
823
  };
811
824
 
812
825
  // package.json
813
- var version = "1.9.2-next.8";
826
+ var version = "1.9.2";
814
827
 
815
828
  // src/index.ts
816
829
  var COPILOTKIT_VERSION = version;
@@ -843,9 +856,11 @@ var COPILOTKIT_VERSION = version;
843
856
  actionParametersToJsonSchema,
844
857
  convertJsonSchemaToZodSchema,
845
858
  dataToUUID,
859
+ ensureStructuredError,
846
860
  executeConditions,
847
861
  getPossibleVersionMismatch,
848
862
  isMacOS,
863
+ isStructuredCopilotKitError,
849
864
  isValidUUID,
850
865
  jsonSchemaToActionParameters,
851
866
  parseJson,