@comake/skl-js-engine
Version:
Standard Knowledge Language Javascript Engine
74 lines • 2.21 kB
TypeScript
import type { ExecutionOptions, ExecutionResult } from '../types';
/**
* Message handler for incoming transport messages
*/
export declare type MessageHandler<T = any> = (message: T) => Promise<any> | any;
/**
* Transport connection status
*/
export declare enum TransportStatus {
disconnected = "disconnected",
connecting = "connecting",
connected = "connected",
error = "error"
}
/**
* Transport events
*/
export interface TransportEvents {
statusChange: (status: TransportStatus) => void;
error: (error: Error) => void;
message: (message: any) => void;
}
/**
* Transport configuration options
*/
export interface TransportConfig {
timeout?: number;
spawnTimeout?: number;
readyTimeout?: number;
retryAttempts?: number;
retryDelay?: number;
}
/**
* Abstract Transport interface for communication between JSExecutor and execution environment
*/
export interface Transport {
/**
* Current transport status
*/
readonly status: TransportStatus;
/**
* Initialize the transport connection
* @param config - Transport configuration
*/
initialize: (config?: TransportConfig) => Promise<void>;
/**
* Send a message through the transport
* @param message - Message to send
* @returns Promise resolving to response
*/
send: <TRequest, TResponse>(message: TRequest) => Promise<TResponse>;
/**
* Register a message handler for incoming messages
* @param handler - Message handler function
*/
onMessage: <T>(handler: MessageHandler<T>) => void;
/**
* Execute code using this transport
* @param code - JavaScript code to execute
* @param args - Arguments to pass to the code
* @param skdsEndpointUrl - SKDS endpoint URL
* @param options - Execution options
*/
execute?: (code: string, args: Record<string, any>, skdsEndpointUrl: string, options: Required<ExecutionOptions>) => Promise<ExecutionResult>;
/**
* Close the transport connection
*/
close: () => Promise<void>;
/**
* Check if the transport is ready for communication
*/
isReady: () => boolean;
}
//# sourceMappingURL=Transport.d.ts.map