rcc-pipeline
Version:
RCC Pipeline Module - Pipeline system and workflow management based on pipeline-framework
191 lines • 5.27 kB
TypeScript
/**
* Pipeline Class - Represents a single pipeline with multiple targets
* 流水线类 - 表示包含多个目标的单一流水线
*/
import { BaseProvider } from './BaseProvider';
import { PipelineTracker } from './PipelineTracker';
import { IRequestContext } from '../interfaces/IRequestContext';
import { IPipelineStage } from '../interfaces/IPipelineStage';
type OperationType = 'chat' | 'streamChat' | 'healthCheck';
export interface PipelineTarget {
id: string;
provider: BaseProvider;
weight: number;
enabled: boolean;
healthStatus: 'healthy' | 'unhealthy' | 'unknown';
lastHealthCheck: number;
requestCount: number;
errorCount: number;
metadata?: Record<string, any>;
}
export interface PipelineConfig {
id: string;
name: string;
virtualModelId: string;
description?: string;
targets: PipelineTarget[];
loadBalancingStrategy: 'round-robin' | 'weighted' | 'least-connections' | 'random';
healthCheckInterval: number;
maxRetries: number;
timeout: number;
metadata?: Record<string, any>;
}
export interface PipelineMetrics {
totalRequests: number;
successfulRequests: number;
failedRequests: number;
averageResponseTime: number;
currentTargets: number;
healthyTargets: number;
unhealthyTargets: number;
errorRate: number;
uptime: number;
lastUsed: number;
}
export interface PipelineExecutionOptions {
timeout?: number;
retries?: number;
requestContext?: IRequestContext;
healthCheck?: boolean;
metadata?: Record<string, any>;
}
export interface PipelineExecutionResult {
pipelineId: string;
targetId: string;
success: boolean;
response?: any;
error?: string;
duration: number;
timestamp: number;
targetMetrics: {
requestCount: number;
errorCount: number;
healthStatus: string;
};
stages?: IPipelineStage[];
}
/**
* Pipeline Class - Manages multiple targets with load balancing
* 流水线类 - 管理多个目标并进行负载均衡
*/
export declare class Pipeline {
config: PipelineConfig;
private targets;
private currentTargetIndex;
private metrics;
private healthCheckInterval?;
private pipelineTracker;
constructor(config: PipelineConfig, pipelineTracker: PipelineTracker);
/**
* Execute a request through the pipeline
* 通过流水线执行请求
*/
execute(request: any, operation: OperationType, options?: PipelineExecutionOptions): Promise<PipelineExecutionResult>;
/**
* Execute streaming request through the pipeline
* 通过流水线执行流式请求
*/
executeStreaming(request: any, operation: OperationType, options?: PipelineExecutionOptions): AsyncGenerator<PipelineExecutionResult, void, unknown>;
/**
* Select target based on load balancing strategy
* 根据负载均衡策略选择目标
*/
private selectTarget;
/**
* Round-robin target selection
* 轮询目标选择
*/
private selectRoundRobin;
/**
* Weighted target selection
* 加权目标选择
*/
private selectWeighted;
/**
* Least connections target selection
* 最少连接目标选择
*/
private selectLeastConnections;
/**
* Random target selection
* 随机目标选择
*/
private selectRandom;
/**
* Execute with timeout
* 带超时执行
*/
private executeWithTimeout;
/**
* Start health checks (simplified - no-op)
* 启动健康检查(简化 - 空操作)
*/
private startHealthChecks;
/**
* Get healthy targets
* 获取健康目标
*/
private getHealthyTargets;
/**
* Get unhealthy targets
* 获取不健康目标
*/
private getUnhealthyTargets;
/**
* Update average response time
* 更新平均响应时间
*/
private updateAverageResponseTime;
/**
* Add target to pipeline
* 向流水线添加目标
*/
addTarget(target: PipelineTarget): void;
/**
* Remove target from pipeline
* 从流水线移除目标
*/
removeTarget(targetId: string): boolean;
/**
* Update target
* 更新目标
*/
updateTarget(targetId: string, updates: Partial<PipelineTarget>): boolean;
/**
* Get pipeline metrics
* 获取流水线指标
*/
getMetrics(): PipelineMetrics;
/**
* Get pipeline config
* 获取流水线配置
*/
getConfig(): PipelineConfig;
/**
* Get all targets
* 获取所有目标
*/
getTargets(): PipelineTarget[];
/**
* Check if pipeline is healthy (simplified - always healthy)
* 检查流水线是否健康(简化 - 总是健康的)
*/
isHealthy(): boolean;
/**
* Get target by ID
* 根据ID获取目标
*/
getTarget(targetId: string): PipelineTarget | undefined;
/**
* Enable/disable target
* 启用/禁用目标
*/
setTargetEnabled(targetId: string, enabled: boolean): boolean;
/**
* Destroy pipeline and cleanup resources
* 销毁流水线并清理资源
*/
destroy(): void;
}
export {};
//# sourceMappingURL=Pipeline.d.ts.map