@layr-labs/hourglass-performer
Version:
TypeScript SDK for building Hourglass AVS performers
124 lines • 3.3 kB
TypeScript
import { TaskRequest } from '../types/performer';
import { ILogger } from '../utils/logger';
/**
* Task execution context containing metadata and utilities
*/
export interface TaskContext {
/** The original task request */
readonly request: TaskRequest;
/** Task start timestamp */
readonly startTime: number;
/** Unique execution ID for this task run */
readonly executionId: string;
/** Logger instance for this task */
readonly logger: ILogger;
/** Cancellation signal */
readonly signal: AbortSignal;
/** Custom metadata storage */
readonly metadata: Map<string, any>;
}
/**
* Task execution result with metadata
*/
export interface TaskExecutionResult {
/** The task response */
result: Uint8Array;
/** Execution duration in milliseconds */
duration: number;
/** Success status */
success: boolean;
/** Error message if failed */
error?: string;
/** Custom metadata */
metadata?: Record<string, any>;
}
/**
* Task processing pipeline stage
*/
export interface TaskProcessingStage {
/** Stage name for logging */
name: string;
/** Execute the stage */
execute(context: TaskContext): Promise<void>;
}
/**
* Task execution metrics
*/
export interface TaskMetrics {
/** Task ID */
taskId: string;
/** Execution ID */
executionId: string;
/** Start timestamp */
startTime: number;
/** End timestamp */
endTime?: number;
/** Duration in milliseconds */
duration?: number;
/** Success status */
success?: boolean;
/** Error message */
error?: string;
/** Payload size in bytes */
payloadSize: number;
/** Result size in bytes */
resultSize?: number;
/** Custom metrics */
customMetrics?: Record<string, number | string>;
}
/**
* Task context builder for creating task execution contexts
*/
export declare class TaskContextBuilder {
private request;
private logger;
private timeout;
private abortController;
constructor(request: TaskRequest, logger: ILogger, timeout?: number);
/**
* Build the task context
*/
build(): TaskContext;
/**
* Cancel the task execution
*/
cancel(): void;
/**
* Generate a unique execution ID
*/
private generateExecutionId;
/**
* Create a task-specific logger
*/
private createTaskLogger;
}
/**
* Task execution pipeline for processing tasks through multiple stages
*/
export declare class TaskPipeline {
private stages;
/**
* Add a processing stage to the pipeline
*/
addStage(stage: TaskProcessingStage): this;
/**
* Execute all stages in the pipeline
*/
execute(context: TaskContext): Promise<void>;
}
/**
* Built-in processing stages
*/
export declare class ValidationStage implements TaskProcessingStage {
private validator;
name: string;
constructor(validator: (context: TaskContext) => Promise<void>);
execute(context: TaskContext): Promise<void>;
}
export declare class MetricsStage implements TaskProcessingStage {
private metricsCollector;
name: string;
constructor(metricsCollector: (metrics: TaskMetrics) => void);
execute(context: TaskContext): Promise<void>;
}
//# sourceMappingURL=taskContext.d.ts.map