vibe-tools
Version:
CLI tools for AI agents
133 lines (132 loc) • 3.55 kB
TypeScript
import { ToolUseBlockParam, TextBlockParam } from '@anthropic-ai/sdk/resources/index.mjs';
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
export interface InternalMessage {
role: 'user' | 'assistant' | 'tool';
content: string | Array<ToolResult | ToolUseBlockParam | TextBlockParam>;
tool_call_id?: string;
name?: string;
cache_control?: {
type: string;
};
}
export interface ToolResult {
type: 'tool_result';
tool_use_id: string;
content: string;
cache_control?: {
type: string;
};
}
export interface ToolCall {
name: string;
args: any;
result: ToolExecutionResult;
tool_use_id: string;
}
export interface ToolDefinition {
name: string;
description: string;
parameters: Record<string, any>;
execute: (args: any) => Promise<ToolExecutionResult>;
}
export interface ToolExecutionResult {
success: boolean;
output: string;
error?: {
message: string;
code?: number;
details?: Record<string, any>;
};
}
export interface UnifiedLLMClientOptions {
provider: 'anthropic' | 'openrouter';
model: string;
debug: boolean;
maxTokens: number;
temperature?: number;
topP?: number;
logger: (message: string) => void;
mcpMode: boolean;
mcpConfig?: StdioServerParameters;
}
/**
* Unified Tool-Enabled LLM Client that supports both Anthropic and OpenRouter
*/
export declare class UnifiedLLMClient {
private anthropicClient?;
private openrouterClient?;
private messages;
private tools;
private toolCalls;
private toolDefinitions;
private config;
private logger;
private mcpClient?;
private transport?;
constructor(options: UnifiedLLMClientOptions, toolDefinitions?: ToolDefinition[]);
processCompletionNoTools(messages: InternalMessage[], systemPrompt: string): Promise<string>;
/**
* Process a user query with tool execution
* @param query The user query to process
* @param systemPrompt The system prompt to use
* @param maxApiCalls Maximum number of API calls allowed (default: 30)
* @returns Array of messages representing the conversation
*/
processQuery(query: string, systemPrompt: string, maxApiCalls?: number): Promise<InternalMessage[]>;
/**
* Process Anthropic message stream
*/
private processAnthropicStream;
/**
* Process OpenRouter message stream
*/
private processOpenRouterStream;
/**
* Initialize the MCP client and transport
*/
private initMCPClient;
/**
* Start the MCP client
*/
startMCP(): Promise<void>;
/**
* Stop the MCP client
*/
stopMCP(): Promise<void>;
/**
* Initialize MCP tools from the server
*/
initMCPTools(): Promise<void>;
/**
* Register a tool with the client
*/
registerTool(tool: ToolDefinition): void;
/**
* Execute a tool call by name and arguments
*/
private executeToolCall;
/**
* Format tool call for logging
*/
private formatToolCall;
/**
* Format tool call arguments for logging
*/
private formatToolCallArgs;
/**
* Generate a unique ID for tool use
*/
private generateToolUseId;
/**
* Get the execution history of tool calls
*/
getExecutionHistory(): Array<{
tool: string;
args: any;
result: ToolExecutionResult;
}>;
/**
* Reset the client state
*/
reset(): void;
}