@comake/skl-js-engine
Version:
Standard Knowledge Language Javascript Engine
193 lines • 4.69 kB
TypeScript
/**
* JSON-RPC 2.0 Protocol Types
* Based on: https://www.jsonrpc.org/specification
*/
/**
* JSON-RPC 2.0 version identifier
*/
export declare const JSONRPC_VERSION: "2.0";
/**
* JSON-RPC request/response identifier
*/
export declare type JsonRpcId = string | number | null;
/**
* JSON-RPC parameters (can be object or array)
*/
export declare type JsonRpcParams = Record<string, any> | any[] | undefined;
/**
* JSON-RPC Error codes (standard codes from spec)
*/
export declare enum JsonRpcErrorCode {
parseError = -32700,
invalidRequest = -32600,
methodNotFound = -32601,
invalidParams = -32602,
internalError = -32603,
serverErrorStart = -32099,
serverErrorEnd = -32000
}
/**
* JSON-RPC Error object
*/
export interface JsonRpcError {
code: JsonRpcErrorCode | number;
message: string;
data?: any;
}
/**
* JSON-RPC Request object
*/
export interface JsonRpcRequest<TParams = JsonRpcParams> {
jsonrpc: typeof JSONRPC_VERSION;
method: string;
params?: TParams;
id: JsonRpcId;
}
/**
* JSON-RPC Notification object (request without id)
*/
export interface JsonRpcNotification<TParams = JsonRpcParams> {
jsonrpc: typeof JSONRPC_VERSION;
method: string;
params?: TParams;
}
/**
* JSON-RPC Success Response object
*/
export interface JsonRpcSuccessResponse<TResult = any> {
jsonrpc: typeof JSONRPC_VERSION;
result: TResult;
id: JsonRpcId;
}
/**
* JSON-RPC Error Response object
*/
export interface JsonRpcErrorResponse {
jsonrpc: typeof JSONRPC_VERSION;
error: JsonRpcError;
id: JsonRpcId;
}
/**
* JSON-RPC Response object (success or error)
*/
export declare type JsonRpcResponse<TResult = any> = JsonRpcSuccessResponse<TResult> | JsonRpcErrorResponse;
/**
* JSON-RPC Message (request, notification, or response)
*/
export declare type JsonRpcMessage<TParams = JsonRpcParams, TResult = any> = JsonRpcRequest<TParams> | JsonRpcNotification<TParams> | JsonRpcResponse<TResult>;
/**
* Method handler function signature
*/
export declare type JsonRpcMethodHandler<TParams = JsonRpcParams, TResult = any> = (params: TParams, id?: JsonRpcId) => Promise<TResult> | TResult;
/**
* Method registry for JSON-RPC handlers
*/
export declare type JsonRpcMethodRegistry = Record<string, JsonRpcMethodHandler>;
/**
* JSON-RPC server configuration
*/
export interface JsonRpcServerConfig {
/**
* Maximum number of concurrent requests
*/
maxConcurrentRequests?: number;
/**
* Request timeout in milliseconds
*/
requestTimeout?: number;
/**
* Whether to validate JSON-RPC format strictly
*/
strictValidation?: boolean;
/**
* Custom error handler
*/
errorHandler?: (error: Error, request?: JsonRpcRequest) => JsonRpcError;
}
/**
* JSON-RPC client configuration
*/
export interface JsonRpcClientConfig {
/**
* Default timeout for requests in milliseconds
*/
defaultTimeout?: number;
/**
* Maximum number of retry attempts
*/
maxRetries?: number;
/**
* Retry delay in milliseconds
*/
retryDelay?: number;
/**
* Whether to generate sequential request IDs
*/
sequentialIds?: boolean;
}
/**
* Pending request tracking
*/
export interface PendingRequest<TResult = any> {
id: JsonRpcId;
method: string;
timestamp: number;
timeout?: number;
resolve: (value: TResult) => void;
reject: (error: Error) => void;
}
/**
* JSON-RPC validation result
*/
export interface ValidationResult {
valid: boolean;
error?: JsonRpcError;
}
/**
* Standard JSON-RPC method names for JSExecutor
*/
export declare const STANDARD_METHODS: {
readonly executeCode: "executeCode";
readonly getStatus: "getStatus";
readonly ping: "ping";
readonly shutdown: "shutdown";
readonly log: "log";
readonly error: "error";
};
/**
* JSExecutor specific request/response types
*/
export interface ExecuteCodeRequest {
code: string;
args: Record<string, any>;
functionName: string;
skdsEndpointUrl: string;
}
export interface ExecuteCodeResponse {
success: boolean;
result?: any;
error?: {
message: string;
name?: string;
stack?: string;
};
logs: string[];
executionTime: number;
}
export interface StatusRequest {
}
export interface StatusResponse {
status: 'ready' | 'busy' | 'error';
uptime: number;
memoryUsage?: {
used: number;
total: number;
};
}
export interface LogNotification {
level: 'info' | 'warn' | 'error' | 'debug';
message: string;
timestamp: number;
data?: any;
}
//# sourceMappingURL=types.d.ts.map