@llumiverse/common
Version:
Public types, enums and options used by Llumiverse API.
303 lines • 10 kB
JavaScript
// ============== Provider details ===============
export var Providers;
(function (Providers) {
Providers["openai"] = "openai";
Providers["openai_compatible"] = "openai_compatible";
Providers["azure_openai"] = "azure_openai";
Providers["azure_foundry"] = "azure_foundry";
Providers["huggingface_ie"] = "huggingface_ie";
Providers["replicate"] = "replicate";
Providers["bedrock"] = "bedrock";
Providers["vertexai"] = "vertexai";
Providers["togetherai"] = "togetherai";
Providers["mistralai"] = "mistralai";
Providers["groq"] = "groq";
Providers["watsonx"] = "watsonx";
Providers["xai"] = "xai";
Providers["anthropic"] = "anthropic";
})(Providers || (Providers = {}));
export const ProviderList = {
openai: {
id: Providers.openai,
name: "OpenAI",
requiresApiKey: true,
requiresEndpointUrl: false,
supportSearch: false,
},
azure_openai: {
id: Providers.azure_openai,
name: "Azure OpenAI",
requiresApiKey: false,
requiresEndpointUrl: true,
supportSearch: false,
},
azure_foundry: {
id: Providers.azure_foundry,
name: "Azure Foundry",
requiresApiKey: true,
requiresEndpointUrl: true,
supportSearch: false,
},
huggingface_ie: {
id: Providers.huggingface_ie,
name: "HuggingFace Inference Endpoint",
requiresApiKey: true,
requiresEndpointUrl: true,
},
replicate: {
id: Providers.replicate,
name: "Replicate",
requiresApiKey: true,
requiresEndpointUrl: false,
supportSearch: true,
},
bedrock: {
id: Providers.bedrock,
name: "AWS Bedrock",
requiresApiKey: false,
requiresEndpointUrl: false,
endpointPlaceholder: "region name (eg. us-east-1)",
supportSearch: false,
},
vertexai: {
id: Providers.vertexai,
name: "Google Agent Platform (Vertex AI)",
requiresApiKey: false,
requiresEndpointUrl: false,
supportSearch: false,
},
togetherai: {
id: Providers.togetherai,
name: "Together AI",
requiresApiKey: false,
requiresEndpointUrl: false,
supportSearch: false,
},
mistralai: {
id: Providers.mistralai,
name: "Mistral AI",
requiresApiKey: false,
requiresEndpointUrl: false,
supportSearch: false,
},
groq: {
id: Providers.groq,
name: "Groq Cloud",
requiresApiKey: false,
requiresEndpointUrl: false,
supportSearch: false,
},
watsonx: {
id: Providers.watsonx,
name: "IBM WatsonX",
requiresApiKey: true,
requiresEndpointUrl: true,
supportSearch: false
},
xai: {
id: Providers.xai,
name: "xAI (Grok)",
requiresApiKey: true,
requiresEndpointUrl: false,
supportSearch: false
},
openai_compatible: {
id: Providers.openai_compatible,
name: "OpenAI Compatible",
requiresApiKey: true,
requiresEndpointUrl: true,
endpointPlaceholder: "https://api.example.com/v1",
supportSearch: false
},
anthropic: {
id: Providers.anthropic,
name: "Anthropic",
requiresApiKey: true,
requiresEndpointUrl: false,
supportSearch: false,
},
};
/**
* Standardized error class for Llumiverse driver errors.
*
* Normalizes errors from different LLM providers (OpenAI, Anthropic, Bedrock, VertexAI, etc.)
* into a consistent format. The primary value is the `retryable` flag, which enables upstream
* consumers to implement smart retry logic.
*
* @example
* ```typescript
* try {
* const result = await driver.execute(segments, options);
* } catch (error) {
* if (LlumiverseError.isLlumiverseError(error)) {
* console.log(`Provider: ${error.context.provider}`);
* console.log(`Model: ${error.context.model}`);
* console.log(`Retryable: ${error.retryable}`);
*
* if (error.retryable) {
* // Implement retry logic with exponential backoff
* await retryWithBackoff(() => driver.execute(segments, options));
* } else {
* // Handle non-retryable error (e.g., invalid API key, malformed request)
* logError(error);
* }
* }
* throw error;
* }
* ```
*/
export class LlumiverseError extends Error {
/**
* HTTP status code (e.g., 429, 500) if available.
* Undefined if the error doesn't have a numeric status code.
*/
code;
/**
* Provider-specific error name/type (e.g., "ThrottlingException", "ValidationException").
* Optional - used to preserve the semantic error type from the provider SDK.
*/
name;
/**
* Whether this error is retryable.
* - True: Definitely retryable (rate limits, timeouts, server errors)
* - False: Definitely not retryable (auth failures, invalid requests, malformed schemas)
* - Undefined: Unknown retryability - allows consumers to decide default behavior
*
* When undefined, consumers can choose their retry strategy:
* - Conservative: Don't retry unknown errors (avoid spam)
* - Resilient: Retry unknown errors (prioritize success)
*/
retryable;
/**
* Context about where and how the error occurred.
* Includes provider, model, operation type.
*/
context;
/**
* The original error from the provider SDK.
* Preserved for debugging and detailed error inspection.
*/
originalError;
constructor(message, retryable, context, originalError, code, name) {
super(message);
this.name = name || 'LlumiverseError';
this.code = code;
this.retryable = retryable;
this.context = context;
this.originalError = originalError;
// Preserve stack trace from original error if available
if (originalError instanceof Error && originalError.stack) {
this.stack = originalError.stack;
}
}
/**
* Serialize the error to JSON for logging or transmission.
* Includes all error properties except the original error object itself.
*/
toJSON() {
return {
name: this.name,
message: this.message,
code: this.code,
retryable: this.retryable,
context: this.context,
stack: this.stack,
// Include original error message if available
originalErrorMessage: this.originalError instanceof Error
? this.originalError.message
: String(this.originalError),
};
}
/**
* Type guard to check if an error is a LlumiverseError.
* Useful for conditional error handling.
*
* @param error - The error to check
* @returns True if the error is a LlumiverseError
*/
static isLlumiverseError(error) {
return error instanceof LlumiverseError;
}
}
//Common names to share between different models
export var SharedOptions;
(function (SharedOptions) {
//Text
SharedOptions["max_tokens"] = "max_tokens";
SharedOptions["temperature"] = "temperature";
SharedOptions["top_p"] = "top_p";
SharedOptions["top_k"] = "top_k";
SharedOptions["presence_penalty"] = "presence_penalty";
SharedOptions["frequency_penalty"] = "frequency_penalty";
SharedOptions["stop_sequence"] = "stop_sequence";
SharedOptions["effort"] = "effort";
//Image
SharedOptions["seed"] = "seed";
SharedOptions["number_of_images"] = "number_of_images";
})(SharedOptions || (SharedOptions = {}));
export var OptionType;
(function (OptionType) {
OptionType["numeric"] = "numeric";
OptionType["enum"] = "enum";
OptionType["boolean"] = "boolean";
OptionType["string_list"] = "string_list";
})(OptionType || (OptionType = {}));
// ============== Prompts ===============
export var PromptRole;
(function (PromptRole) {
PromptRole["safety"] = "safety";
PromptRole["system"] = "system";
PromptRole["user"] = "user";
PromptRole["assistant"] = "assistant";
PromptRole["negative"] = "negative";
PromptRole["mask"] = "mask";
/**
* Used to send the response of a tool
*/
PromptRole["tool"] = "tool";
})(PromptRole || (PromptRole = {}));
/**
* @deprecated This is deprecated. Use CompletionResult.type information instead.
*/
export var Modalities;
(function (Modalities) {
Modalities["text"] = "text";
Modalities["image"] = "image";
})(Modalities || (Modalities = {}));
export var AIModelStatus;
(function (AIModelStatus) {
AIModelStatus["Available"] = "available";
AIModelStatus["Pending"] = "pending";
AIModelStatus["Stopped"] = "stopped";
AIModelStatus["Unavailable"] = "unavailable";
AIModelStatus["Unknown"] = "unknown";
AIModelStatus["Legacy"] = "legacy";
})(AIModelStatus || (AIModelStatus = {}));
export var ModelType;
(function (ModelType) {
ModelType["Classifier"] = "classifier";
ModelType["Regressor"] = "regressor";
ModelType["Clustering"] = "clustering";
ModelType["AnomalyDetection"] = "anomaly-detection";
ModelType["TimeSeries"] = "time-series";
ModelType["Text"] = "text";
ModelType["Image"] = "image";
ModelType["Audio"] = "audio";
ModelType["Video"] = "video";
ModelType["Embedding"] = "embedding";
ModelType["Chat"] = "chat";
ModelType["Code"] = "code";
ModelType["NLP"] = "nlp";
ModelType["MultiModal"] = "multi-modal";
ModelType["Test"] = "test";
ModelType["Other"] = "other";
ModelType["Unknown"] = "unknown";
})(ModelType || (ModelType = {}));
export var TrainingJobStatus;
(function (TrainingJobStatus) {
TrainingJobStatus["running"] = "running";
TrainingJobStatus["succeeded"] = "succeeded";
TrainingJobStatus["failed"] = "failed";
TrainingJobStatus["cancelled"] = "cancelled";
})(TrainingJobStatus || (TrainingJobStatus = {}));
//# sourceMappingURL=types.js.map