@future-agi/sdk
Version:
We help GenAI teams maintain high-accuracy for their Models in production.
323 lines • 11.4 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateNotFound = exports.TemplateAlreadyExists = exports.UnsupportedFileType = exports.FileNotFoundException = exports.MissingRequiredConfigForEvalTemplate = exports.MissingRequiredKey = exports.InvalidSupportedType = exports.InvalidValueType = exports.InvalidNumberOfEmbeddings = exports.InvalidAdditionalHeaders = exports.InvalidAuthError = exports.MissingAuthError = exports.ServiceUnavailableError = exports.ServerError = exports.RateLimitError = exports.DatasetValidationError = exports.DatasetAuthError = exports.DatasetNotFoundError = exports.DatasetError = exports.SDKException = void 0;
/**
* Base exception for all SDK errors.
*/
class SDKException extends Error {
constructor(message, cause) {
super(message || (cause ? `An SDK error occurred, caused by: ${cause.message}` : 'An unknown error occurred in the SDK.'));
this.name = this.constructor.name;
this.customMessage = message;
this.cause = cause;
// Set the prototype explicitly to maintain instanceof checks
Object.setPrototypeOf(this, new.target.prototype);
}
getMessage() {
if (this.customMessage) {
return this.customMessage;
}
if (this.cause) {
return `An SDK error occurred, caused by: ${this.cause.message}`;
}
return 'An unknown error occurred in the SDK.';
}
getErrorCode() {
return 'UNKNOWN_SDK_ERROR';
}
toString() {
return `${this.name}(message='${this.getMessage()}', code='${this.getErrorCode()}')`;
}
}
exports.SDKException = SDKException;
/**
* Base exception for all dataset operations.
*/
class DatasetError extends SDKException {
getMessage() {
return 'Invalid Dataset Operation.';
}
getErrorCode() {
return 'DATASET_OPERATION_INVALID';
}
}
exports.DatasetError = DatasetError;
/**
* Raised when a dataset cannot be found.
*/
class DatasetNotFoundError extends DatasetError {
getMessage() {
return 'No Existing Dataset Found for Current Dataset Name.';
}
getErrorCode() {
return 'DATASET_NOT_FOUND';
}
}
exports.DatasetNotFoundError = DatasetNotFoundError;
/**
* Raised when authentication fails for dataset operations (e.g., invalid API key).
*/
class DatasetAuthError extends DatasetError {
getMessage() {
return 'Invalid Dataset Authentication, please check your API key and Secret key.';
}
getErrorCode() {
return 'DATASET_AUTH_ERROR';
}
}
exports.DatasetAuthError = DatasetAuthError;
/**
* Raised when input data fails validation.
*/
class DatasetValidationError extends DatasetError {
getMessage() {
return 'Invalid Dataset Validation, please check your input data.';
}
getErrorCode() {
return 'DATASET_VALIDATION_ERROR';
}
}
exports.DatasetValidationError = DatasetValidationError;
/**
* Raised when API rate limits are exceeded.
*/
class RateLimitError extends DatasetError {
getMessage() {
return 'Rate Limit Exceeded, please contact FutureAGI support at support@futureagi.com or check your current plan.';
}
getErrorCode() {
return 'RATE_LIMIT_EXCEEDED';
}
}
exports.RateLimitError = RateLimitError;
/**
* Raised for server-side errors.
*/
class ServerError extends DatasetError {
getMessage() {
return 'Internal Server Error, please contact FutureAGI support at support@futureagi.com.';
}
getErrorCode() {
return 'SERVER_ERROR';
}
}
exports.ServerError = ServerError;
/**
* Raised when the service is temporarily unavailable.
*/
class ServiceUnavailableError extends DatasetError {
getMessage() {
return 'Service Unavailable, please try again later.';
}
getErrorCode() {
return 'SERVICE_UNAVAILABLE';
}
}
exports.ServiceUnavailableError = ServiceUnavailableError;
/**
* Raised when required authentication credentials are missing.
*/
class MissingAuthError extends SDKException {
constructor(fiApiKey, fiSecretKey, cause) {
super(undefined, cause);
this.missingApiKey = !fiApiKey;
this.missingSecretKey = !fiSecretKey;
}
getMessage() {
const missing = [];
if (this.missingApiKey) {
missing.push("'fi_api_key'");
}
if (this.missingSecretKey) {
missing.push("'fi_secret_key'");
}
return `FI Client could not obtain credentials. You can pass your fi_api_key and fi_secret_key ` +
`directly to the FI Client, or you can set environment variables which will be read if the ` +
`keys are not directly passed. ` +
`To set the environment variables use the following variable names: \n` +
` - ${process.env.FI_API_KEY_NAME || 'FI_API_KEY'} for the api key\n` +
` - ${process.env.FI_SECRET_KEY_NAME || 'FI_SECRET_KEY'} for the secret key\n` +
`Missing: ${missing.join(', ')}`;
}
getErrorCode() {
return 'MISSING_FI_CLIENT_AUTHENTICATION';
}
}
exports.MissingAuthError = MissingAuthError;
/**
* Exception raised when API authentication fails due to invalid credentials.
*/
class InvalidAuthError extends SDKException {
constructor(message, cause) {
super(message || 'Invalid FI Client Authentication, please check your API key and secret key.', cause);
}
getMessage() {
return this.customMessage || 'Invalid FI Client Authentication, please check your API key and secret key.';
}
getErrorCode() {
return 'INVALID_FI_CLIENT_AUTHENTICATION';
}
}
exports.InvalidAuthError = InvalidAuthError;
class TemplateNotFound extends SDKException {
constructor(templateName, message, cause) {
super(message || `Template with name '${templateName}' not found.`, cause);
this.templateName = templateName;
}
getErrorCode() {
return 'TEMPLATE_NOT_FOUND';
}
}
exports.TemplateNotFound = TemplateNotFound;
/**
* Exception raised when additional headers are invalid.
*/
class InvalidAdditionalHeaders extends SDKException {
constructor(invalidHeaders, cause) {
super(undefined, cause);
this.invalidHeaderNames = invalidHeaders;
}
getMessage() {
return `Found invalid additional header, cannot use reserved headers named: ${this.invalidHeaderNames.join(', ')}.`;
}
getErrorCode() {
return 'INVALID_ADDITIONAL_HEADERS';
}
}
exports.InvalidAdditionalHeaders = InvalidAdditionalHeaders;
/**
* Exception raised when the number of embeddings is invalid.
*/
class InvalidNumberOfEmbeddings extends SDKException {
constructor(numberOfEmbeddings, maxEmbeddings = 30, cause) {
super(undefined, cause);
this.numberOfEmbeddings = numberOfEmbeddings;
this.maxEmbeddings = maxEmbeddings;
}
getMessage() {
return `The schema contains ${this.numberOfEmbeddings} different embeddings when a maximum of ${this.maxEmbeddings} is allowed.`;
}
getErrorCode() {
return 'INVALID_NUMBER_OF_EMBEDDINGS';
}
}
exports.InvalidNumberOfEmbeddings = InvalidNumberOfEmbeddings;
/**
* Exception raised when the value type is invalid.
*/
class InvalidValueType extends SDKException {
constructor(valueName, value, correctType, cause) {
const message = `${valueName} with value ${JSON.stringify(value)} is of type ${typeof value}, but expected from ${correctType}.`;
super(message, cause);
this.valueName = valueName;
this.value = value;
this.correctType = correctType;
}
getMessage() {
return `${this.valueName} with value ${JSON.stringify(this.value)} is of type ${typeof this.value}, but expected from ${this.correctType}.`;
}
getErrorCode() {
return 'INVALID_VALUE_TYPE';
}
}
exports.InvalidValueType = InvalidValueType;
/**
* Exception raised when the supported type is invalid.
*/
class InvalidSupportedType extends SDKException {
constructor(valueName, value, correctType, cause) {
super(undefined, cause);
this.valueName = valueName;
this.value = value;
this.correctType = correctType;
}
getMessage() {
return `${this.valueName} with value ${JSON.stringify(this.value)} is not supported as of now. Supported types/values are: ${this.correctType}.`;
}
getErrorCode() {
return 'UNSUPPORTED_TYPE_OR_VALUE';
}
}
exports.InvalidSupportedType = InvalidSupportedType;
/**
* Exception raised when a required key is missing.
*/
class MissingRequiredKey extends SDKException {
constructor(fieldName, missingKey, cause) {
const message = `Missing required key '${missingKey}' in ${fieldName}. Please check your configuration or API documentation.`;
super(message, cause);
this.fieldName = fieldName;
this.missingKey = missingKey;
}
getErrorCode() {
return 'MISSING_REQUIRED_KEY';
}
}
exports.MissingRequiredKey = MissingRequiredKey;
/**
* Exception raised when required config for eval template is missing.
*/
class MissingRequiredConfigForEvalTemplate extends SDKException {
constructor(missingKey, evalTemplateName, cause) {
const message = `Missing required config '${missingKey}' for eval template '${evalTemplateName}'.`;
super(message, cause);
this.missingKey = missingKey;
this.evalTemplateName = evalTemplateName;
}
getErrorCode() {
return 'MISSING_EVAL_TEMPLATE_CONFIG';
}
}
exports.MissingRequiredConfigForEvalTemplate = MissingRequiredConfigForEvalTemplate;
/**
* Exception raised when a file is not found.
*/
class FileNotFoundException extends SDKException {
constructor(filePath, message, cause) {
super(message || FileNotFoundException.generateMessage(filePath), cause);
this.filePath = filePath;
}
static generateMessage(filePath) {
if (Array.isArray(filePath)) {
const displayPaths = filePath.slice(0, 3);
let pathsStr = displayPaths.join(', ');
if (filePath.length > 3) {
pathsStr += `, and ${filePath.length - 3} more`;
}
return `Files not found: ${pathsStr}.`;
}
return `File not found: ${filePath}.`;
}
getErrorCode() {
return 'FILE_NOT_FOUND';
}
}
exports.FileNotFoundException = FileNotFoundException;
/**
* Exception raised when a file type is not supported.
*/
class UnsupportedFileType extends SDKException {
constructor(fileExt, fileName, message, cause) {
super(message || `Unsupported file type: '.${fileExt}' for file '${fileName}'.`, cause);
this.fileExt = fileExt;
this.fileName = fileName;
}
getErrorCode() {
return 'UNSUPPORTED_FILE_TYPE';
}
}
exports.UnsupportedFileType = UnsupportedFileType;
/**
* Exception raised when a template already exists.
*/
class TemplateAlreadyExists extends SDKException {
constructor(templateName, message, cause) {
super(message || `Template '${templateName}' already exists. Please use a different name to create a new template.`, cause);
this.templateName = templateName;
}
getErrorCode() {
return 'TEMPLATE_ALREADY_EXISTS';
}
}
exports.TemplateAlreadyExists = TemplateAlreadyExists;
//# sourceMappingURL=errors.js.map
;