@copilotkit/shared
Version:
<div align="center"> <a href="https://copilotkit.ai" target="_blank"> <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo"> </a>
227 lines (224 loc) • 8.09 kB
TypeScript
import { GraphQLError } from 'graphql';
declare enum Severity {
Error = "error"
}
declare const ERROR_NAMES: {
readonly COPILOT_ERROR: "CopilotError";
readonly COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError";
readonly COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError";
readonly COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError";
readonly COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError";
readonly COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError";
readonly RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError";
readonly CONFIGURATION_ERROR: "ConfigurationError";
readonly MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError";
readonly UPGRADE_REQUIRED_ERROR: "UpgradeRequiredError";
};
declare const COPILOT_CLOUD_ERROR_NAMES: ("ConfigurationError" | "MissingPublicApiKeyError" | "UpgradeRequiredError")[];
declare enum CopilotKitErrorCode {
NETWORK_ERROR = "NETWORK_ERROR",
NOT_FOUND = "NOT_FOUND",
AGENT_NOT_FOUND = "AGENT_NOT_FOUND",
API_NOT_FOUND = "API_NOT_FOUND",
REMOTE_ENDPOINT_NOT_FOUND = "REMOTE_ENDPOINT_NOT_FOUND",
MISUSE = "MISUSE",
UNKNOWN = "UNKNOWN",
VERSION_MISMATCH = "VERSION_MISMATCH",
CONFIGURATION_ERROR = "CONFIGURATION_ERROR",
MISSING_PUBLIC_API_KEY_ERROR = "MISSING_PUBLIC_API_KEY_ERROR",
UPGRADE_REQUIRED_ERROR = "UPGRADE_REQUIRED_ERROR"
}
declare const ERROR_CONFIG: {
NETWORK_ERROR: {
statusCode: number;
troubleshootingUrl: string;
};
NOT_FOUND: {
statusCode: number;
troubleshootingUrl: string;
};
AGENT_NOT_FOUND: {
statusCode: number;
troubleshootingUrl: string;
};
API_NOT_FOUND: {
statusCode: number;
troubleshootingUrl: string;
};
REMOTE_ENDPOINT_NOT_FOUND: {
statusCode: number;
troubleshootingUrl: string;
};
MISUSE: {
statusCode: number;
troubleshootingUrl: null;
};
UNKNOWN: {
statusCode: number;
};
CONFIGURATION_ERROR: {
statusCode: number;
troubleshootingUrl: null;
severity: Severity;
};
MISSING_PUBLIC_API_KEY_ERROR: {
statusCode: number;
troubleshootingUrl: null;
severity: Severity;
};
UPGRADE_REQUIRED_ERROR: {
statusCode: number;
troubleshootingUrl: null;
severity: Severity;
};
VERSION_MISMATCH: {
statusCode: number;
troubleshootingUrl: null;
};
};
declare class CopilotKitError extends GraphQLError {
code: CopilotKitErrorCode;
statusCode: number;
severity?: Severity;
constructor({ message, code, severity, }: {
message?: string;
code: CopilotKitErrorCode;
severity?: Severity;
});
}
/**
* Error thrown when we can identify wrong usage of our components.
* This helps us notify the developer before real errors can happen
*
* @extends CopilotKitError
*/
declare class CopilotKitMisuseError extends CopilotKitError {
constructor({ message, code, }: {
message: string;
code?: CopilotKitErrorCode;
});
}
/**
* Error thrown when CPK versions does not match
*
* @extends CopilotKitError
*/
declare class CopilotKitVersionMismatchError extends CopilotKitError {
constructor({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion, }: VersionMismatchResponse);
}
/**
* Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
* This typically occurs when:
* - The API endpoint URL is invalid or misconfigured
* - The API service is not running at the expected location
* - There are network/firewall issues preventing access
*
* @extends CopilotKitError
*/
declare class CopilotKitApiDiscoveryError extends CopilotKitError {
constructor(params?: {
message?: string;
code?: CopilotKitErrorCode.API_NOT_FOUND | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;
url?: string;
});
}
/**
* This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted
* This typically occurs when:
* - The API endpoint URL is invalid or misconfigured
* - The API service is not running at the expected location
*
* @extends CopilotKitApiDiscoveryError
*/
declare class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {
constructor(params?: {
message?: string;
url?: string;
});
}
/**
* Error thrown when a LangGraph agent cannot be found or accessed.
* This typically occurs when:
* - The specified agent name does not exist in the deployment
* - The agent configuration is invalid or missing
* - The agent service is not properly deployed or initialized
*
* @extends CopilotKitError
*/
declare class CopilotKitAgentDiscoveryError extends CopilotKitError {
constructor(params: {
agentName?: string;
availableAgents: {
name: string;
id: string;
}[];
});
}
/**
* Handles low-level networking errors that occur before a request reaches the server.
* These errors arise from issues in the underlying communication infrastructure rather than
* application-level logic or server responses. Typically used to handle "fetch failed" errors
* where no HTTP status code is available.
*
* Common scenarios include:
* - Connection failures (ECONNREFUSED) when server is down/unreachable
* - DNS resolution failures (ENOTFOUND) when domain can't be resolved
* - Timeouts (ETIMEDOUT) when request takes too long
* - Protocol/transport layer errors like SSL/TLS issues
*/
declare class CopilotKitLowLevelError extends CopilotKitError {
constructor({ error, url, message }: {
error: Error;
url: string;
message?: string;
});
}
/**
* Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.
* Used when we receive an HTTP error status and wish to handle broad range of them
*
* This differs from CopilotKitLowLevelError in that:
* - ResolvedCopilotKitError: Server was reached and returned an HTTP status
* - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)
*
* @param status - The HTTP status code received from the API response
* @param message - Optional error message to include
* @param code - Optional specific CopilotKitErrorCode to override default behavior
*
* Default behavior:
* - 400 Bad Request: Maps to CopilotKitApiDiscoveryError
* - All other status codes: Maps to UNKNOWN error code if no specific code provided
*/
declare class ResolvedCopilotKitError extends CopilotKitError {
constructor({ status, message, code, isRemoteEndpoint, url, }: {
status: number;
message?: string;
code?: CopilotKitErrorCode;
isRemoteEndpoint?: boolean;
url?: string;
});
}
declare class ConfigurationError extends CopilotKitError {
constructor(message: string);
}
declare class MissingPublicApiKeyError extends ConfigurationError {
constructor(message: string);
}
declare class UpgradeRequiredError extends ConfigurationError {
constructor(message: string);
}
interface VersionMismatchResponse {
runtimeVersion?: string;
runtimeClientGqlVersion: string;
reactCoreVersion: string;
}
declare function getPossibleVersionMismatch({ runtimeVersion, runtimeClientGqlVersion, }: {
runtimeVersion?: string;
runtimeClientGqlVersion: string;
}): Promise<{
runtimeVersion: string;
runtimeClientGqlVersion: string;
reactCoreVersion: string;
message: string;
} | undefined>;
export { COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, getPossibleVersionMismatch };