UNPKG

erosolar-cli

Version:

Unified AI agent framework for the command line - Multi-provider support with schema-driven tools, code intelligence, and transparent reasoning

306 lines 9.1 kB
/** * AI Provider identifier for multi-provider support */ export type ProviderId = string; /** * Reasoning effort levels for AI model optimization */ export type ReasoningEffortLevel = 'low' | 'medium' | 'high'; /** * Text verbosity levels for output control */ export type TextVerbosityLevel = 'low' | 'medium' | 'high'; /** * Conversation roles in AI message flow */ export type ConversationRole = 'system' | 'user' | 'assistant' | 'tool'; export interface SystemMessage { role: 'system'; content: string; } export interface UserMessage { role: 'user'; content: string; } export interface ToolCallArguments { [key: string]: unknown; } export interface ToolCallRequest { id: string; name: string; arguments: ToolCallArguments; } export interface AssistantMessage { role: 'assistant'; content: string; toolCalls?: ToolCallRequest[]; } export interface ToolMessage { role: 'tool'; name: string; content: string; toolCallId: string; } /** * Enhanced discriminated union for type-safe tool responses * Provides comprehensive error handling and metadata tracking */ export interface ToolSuccessResponse { readonly type: 'success'; readonly content: string; readonly metadata?: { readonly linesRead?: number; readonly fileSize?: number; readonly executionTime?: number; readonly cacheHit?: boolean; readonly toolName?: string; readonly timestamp?: number; }; } /** * Structured error response with recovery guidance */ export interface ToolErrorResponse { readonly type: 'error'; readonly error: { readonly code: string; readonly message: string; readonly details?: Readonly<Record<string, unknown>>; readonly suggestion?: string; readonly recoverable: boolean; readonly toolName?: string; }; } /** * Warning response with actionable suggestions */ export interface ToolWarningResponse { readonly type: 'warning'; readonly content: string; readonly warnings: ReadonlyArray<{ readonly code: string; readonly message: string; readonly severity: 'critical' | 'warning' | 'info'; readonly suggestion: string; }>; } /** * Progress update for long-running operations */ export interface ToolProgressResponse { readonly type: 'progress'; readonly progress: number; readonly message: string; readonly metadata?: { readonly estimatedRemaining?: number; readonly currentStep?: string; }; } /** * Comprehensive tool response union for AI flow control */ export type ToolResponse = ToolSuccessResponse | ToolErrorResponse | ToolWarningResponse | ToolProgressResponse; /** * Type guard for successful tool responses */ export declare function isToolSuccess(response: ToolResponse): response is ToolSuccessResponse; /** * Type guard for error tool responses */ export declare function isToolError(response: ToolResponse): response is ToolErrorResponse; /** * Type guard for warning tool responses */ export declare function isToolWarning(response: ToolResponse): response is ToolWarningResponse; /** * Type guard for progress tool responses */ export declare function isToolProgress(response: ToolResponse): response is ToolProgressResponse; export type ConversationMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage; /** * Base interface for all JSON Schema property definitions */ export interface JSONSchemaPropertyBase { readonly description?: string; readonly nullable?: boolean; readonly deprecated?: boolean; readonly readOnly?: boolean; readonly writeOnly?: boolean; } /** * String schema with validation constraints */ export interface JSONSchemaString extends JSONSchemaPropertyBase { readonly type: 'string'; readonly enum?: ReadonlyArray<string>; readonly minLength?: number; readonly maxLength?: number; readonly pattern?: string; readonly format?: 'date-time' | 'email' | 'uri' | 'uuid' | 'hostname'; readonly default?: string; } /** * Number schema with validation constraints */ export interface JSONSchemaNumber extends JSONSchemaPropertyBase { readonly type: 'number'; readonly minimum?: number; readonly maximum?: number; readonly exclusiveMinimum?: number; readonly exclusiveMaximum?: number; readonly multipleOf?: number; readonly default?: number; } /** * Boolean schema */ export interface JSONSchemaBoolean extends JSONSchemaPropertyBase { readonly type: 'boolean'; readonly default?: boolean; } /** * Array schema with item validation */ export interface JSONSchemaArray extends JSONSchemaPropertyBase { readonly type: 'array'; readonly items: JSONSchemaProperty; readonly minItems?: number; readonly maxItems?: number; readonly uniqueItems?: boolean; } /** * Union type for all JSON Schema property types */ export type JSONSchemaProperty = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaArray | JSONSchemaObject; /** * Object schema with property validation */ export interface JSONSchemaObject extends JSONSchemaPropertyBase { readonly type: 'object'; readonly properties?: Readonly<Record<string, JSONSchemaProperty>>; readonly required?: ReadonlyArray<string>; readonly additionalProperties?: boolean; readonly minProperties?: number; readonly maxProperties?: number; } /** * Definition of a tool available to AI providers */ export interface ProviderToolDefinition { readonly name: string; readonly description: string; readonly parameters?: JSONSchemaObject; } /** * Token usage statistics from AI provider */ export interface ProviderUsage { readonly inputTokens?: number; readonly outputTokens?: number; readonly totalTokens?: number; } /** * Why the model stopped generating - critical for agentic loop control */ export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence'; /** * Base interface for all provider responses */ export interface ProviderResponseBase { readonly usage?: ProviderUsage | null; /** Why the model stopped - determines if auto-continuation is needed */ readonly stopReason?: StopReason; } /** * Discriminated union for provider responses */ export type ProviderResponse = (ProviderResponseBase & { readonly type: 'message'; readonly content: string; }) | (ProviderResponseBase & { readonly type: 'tool_calls'; readonly toolCalls: ToolCallRequest[]; readonly content?: string; }); /** * Streaming chunk for real-time AI responses */ export interface StreamChunk { readonly type: 'content' | 'tool_call' | 'usage' | 'done'; readonly content?: string; readonly toolCall?: ToolCallRequest; readonly usage?: ProviderUsage; /** Stop reason from the final message - included with 'done' chunk */ readonly stopReason?: StopReason; } /** * AI Provider interface for multi-provider support */ export interface LLMProvider { readonly id: ProviderId; readonly model: string; generate(messages: ConversationMessage[], tools: ProviderToolDefinition[]): Promise<ProviderResponse>; generateStream?(messages: ConversationMessage[], tools: ProviderToolDefinition[]): AsyncIterableIterator<StreamChunk>; getCapabilities?(): ProviderCapabilities; } /** * Capabilities of an AI provider */ export interface ProviderCapabilities { readonly streaming: boolean; readonly toolCalling: boolean; readonly vision: boolean; readonly functionCalling: boolean; readonly maxTokens: number; readonly supportedModalities: ReadonlyArray<'text' | 'image' | 'audio'>; } /** * Type-safe Result pattern for error handling * Eliminates the need for try-catch blocks and provides compile-time safety */ export type Result<T, E = Error> = { readonly ok: true; readonly value: T; } | { readonly ok: false; readonly error: E; }; /** * Type guard for successful Result */ export declare function isOk<T, E>(result: Result<T, E>): result is { readonly ok: true; readonly value: T; }; /** * Type guard for failed Result */ export declare function isErr<T, E>(result: Result<T, E>): result is { readonly ok: false; readonly error: E; }; /** * Creates a successful Result */ export declare function ok<T>(value: T): Result<T, never>; /** * Creates a failed Result */ export declare function err<E>(error: E): Result<never, E>; /** * Unwraps a Result, throwing if it's an error */ export declare function unwrap<T, E>(result: Result<T, E>): T; /** * Unwraps a Result, returning a default value if it's an error */ export declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T; /** * Maps a successful Result to a new value */ export declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>; /** * Maps an error Result to a new error */ export declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>; //# sourceMappingURL=types.d.ts.map