@tehreet/conduit
Version:
LLM API gateway with intelligent routing, robust process management, and health monitoring
256 lines • 6.55 kB
TypeScript
export interface ConduitConfig {
preset?: string;
presetConfig?: ConfigPreset;
Providers?: ProviderConfig[];
Router?: RouterConfig;
plugins?: PluginConfig[];
server?: ServerConfig;
monitoring?: MonitoringConfig;
integrations?: IntegrationsConfig;
}
export interface ServerConfig {
port?: number;
host?: string;
cors?: boolean;
healthCheck?: boolean;
gracefulShutdown?: boolean;
timeout?: number;
maxConnections?: number;
keepAlive?: boolean;
}
export interface ProviderConfig {
name: string;
api_base_url: string;
api_key: string;
models: string[];
transformer?: {
use: string[];
};
rateLimit?: {
requestsPerMinute: number;
concurrentRequests: number;
};
}
export interface RouterConfig {
default?: string;
longContext?: string;
background?: string;
think?: string;
customRules?: RoutingRule[];
fallbackStrategy?: 'default' | 'round-robin' | 'least-cost';
}
export interface RoutingRule {
id: string;
name: string;
condition: string;
model: string;
priority: number;
enabled: boolean;
conditions?: RuleCondition[];
}
export interface RuleCondition {
field: string;
operator: 'gt' | 'lt' | 'eq' | 'contains' | 'matches' | 'gte' | 'lte';
value: any;
}
export interface RoutingContext {
request: any;
tokenCount: number;
config: ConduitConfig;
env: NodeJS.ProcessEnv;
synapseContext?: SynapseContext;
metadata?: Record<string, any>;
}
export interface SynapseContext {
projectId?: string;
agentId?: string;
agentType?: string;
projectModelConfig?: string;
agentModelConfig?: string;
}
export interface RoutingDecision {
model: string;
source: 'synapse-context' | 'plugin' | 'preset-rule' | 'token-based' | 'default';
reason: string;
tokenCount?: number;
metadata?: Record<string, any>;
}
export interface PluginConfig {
name: string;
enabled: boolean;
config?: any;
source?: 'file' | 'npm' | 'inline' | 'builtin';
path?: string;
module?: ConduitPlugin;
priority?: number;
}
export interface ConduitPlugin {
name: string;
version: string;
description?: string;
onLoad?(): Promise<void>;
onUnload?(): Promise<void>;
beforeRouting?(context: RoutingContext): Promise<RoutingContext>;
afterRouting?(decision: RoutingDecision): Promise<RoutingDecision>;
customRouter?(context: RoutingContext): Promise<RoutingDecision | null>;
getHealth?(): Promise<HealthStatus>;
validateConfig?(config: any): boolean;
}
export interface MonitoringConfig {
enabled?: boolean;
usage?: {
enabled: boolean;
storage?: 'memory' | 'file' | 'database';
retention?: number;
};
health?: {
enabled: boolean;
interval?: number;
checks?: string[];
};
metrics?: {
enabled: boolean;
provider?: 'prometheus' | 'statsd' | 'custom';
endpoint?: string;
};
}
export interface HealthStatus {
healthy: boolean;
checks: Record<string, HealthCheckResult>;
uptime: number;
startTime: Date;
version?: string;
}
export interface HealthCheckResult {
healthy: boolean;
error?: string;
timestamp: Date;
duration?: number;
metadata?: Record<string, any>;
}
export interface UsageData {
id: string;
timestamp: Date;
projectId?: string;
agentId?: string;
model: string;
tokenCount: number;
cost?: number;
routingReason: string;
metadata?: Record<string, any>;
}
export interface ConfigPreset {
name: string;
description: string;
config: Partial<ConduitConfig>;
defaultRouting?: {
rules: RoutingRule[];
fallback: string;
};
providers?: ProviderConfig[];
plugins?: PluginConfig[];
}
export interface IntegrationsConfig {
synapse?: {
enabled: boolean;
contextExtraction?: {
enabled: boolean;
envVars?: string[];
};
usageTracking?: {
enabled: boolean;
projectLevel: boolean;
agentLevel: boolean;
};
};
}
export interface EnhancedServerConfig extends ServerConfig {
initialConfig?: ConduitConfig;
autoStart?: boolean;
pluginDir?: string;
logging?: {
level?: 'debug' | 'info' | 'warn' | 'error';
format?: 'json' | 'text';
destination?: 'console' | 'file' | 'both';
};
}
export interface WrapperOptions {
claudeBinaryPath: string;
config: ConduitConfig;
loggingEnabled?: boolean;
metricsEnabled?: boolean;
}
export interface ClaudeArgs {
model?: string;
messages?: Array<{
role: string;
content: string;
}>;
systemPrompt?: string;
outputFormat?: string;
thinking?: boolean;
[key: string]: any;
}
export interface ValidationResult {
valid: boolean;
errors: ValidationError[];
warnings: ValidationWarning[];
}
export interface ValidationError {
field: string;
message: string;
value?: any;
}
export interface ValidationWarning {
field: string;
message: string;
value?: any;
}
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
export type ConfigUpdate = DeepPartial<ConduitConfig>;
export interface ConduitEvent {
type: string;
timestamp: Date;
data: any;
}
export interface RoutingEvent extends ConduitEvent {
type: 'routing-decision';
data: {
context: RoutingContext;
decision: RoutingDecision;
};
}
export interface UsageEvent extends ConduitEvent {
type: 'usage';
data: UsageData;
}
export interface HealthEvent extends ConduitEvent {
type: 'health-check';
data: HealthStatus;
}
export type HealthCheck = () => Promise<HealthCheckResult>;
export type ConfigValidator = (config: any) => ValidationResult;
export type RoutingFunction = (context: RoutingContext) => Promise<RoutingDecision>;
export type PluginLoader = (config: PluginConfig) => Promise<ConduitPlugin>;
export declare enum LogLevel {
DEBUG = "debug",
INFO = "info",
WARN = "warn",
ERROR = "error"
}
export declare enum RoutingSource {
SYNAPSE_CONTEXT = "synapse-context",
PLUGIN = "plugin",
PRESET_RULE = "preset-rule",
TOKEN_BASED = "token-based",
DEFAULT = "default"
}
export declare enum PluginSource {
FILE = "file",
NPM = "npm",
INLINE = "inline",
BUILTIN = "builtin"
}
//# sourceMappingURL=index.d.ts.map