@robota-sdk/anthropic
Version:
Anthropic Claude integration for Robota SDK - Claude 3, Claude 2, function calling, and tool integration with Anthropic's API
107 lines (101 loc) • 3.37 kB
TypeScript
import Anthropic from '@anthropic-ai/sdk';
import { BaseAIProvider, UniversalMessage as UniversalMessage$1, ChatOptions as ChatOptions$1 } from '@robota-sdk/agents';
/**
* Valid provider option value types
*/
type ProviderOptionValue = string | number | boolean | undefined | null | Anthropic | ProviderOptionValue[] | {
[key: string]: ProviderOptionValue;
};
/**
* Base provider options interface
*/
interface ProviderOptions {
/**
* Additional provider-specific options
*/
[key: string]: ProviderOptionValue;
}
/**
* Anthropic provider options
*
* Note: Anthropic API doesn't support response format configuration.
* JSON output can be requested through prompt instructions.
*/
interface AnthropicProviderOptions extends ProviderOptions {
/**
* Anthropic API key (required when client is not provided)
*/
apiKey?: string;
/**
* API request timeout (milliseconds)
*/
timeout?: number;
/**
* API base URL
*/
baseURL?: string;
/**
* Anthropic client instance (optional: will be created from apiKey if not provided)
*/
client?: Anthropic;
}
type UniversalMessage = UniversalMessage$1;
type ChatOptions = ChatOptions$1;
/**
* Anthropic provider implementation for Robota
*
* IMPORTANT PROVIDER-SPECIFIC RULES:
* 1. This provider MUST extend BaseAIProvider from @robota-sdk/agents
* 2. Content handling for Anthropic API:
* - When tool_calls are present: content MUST be null (not empty string)
* - For regular assistant messages: content should be a string
* 3. Use override keyword for all methods inherited from BaseAIProvider
* 4. Provider-specific API behavior should be documented here
*
* @public
*/
declare class AnthropicProvider extends BaseAIProvider {
readonly name = "anthropic";
readonly version = "1.0.0";
private readonly client;
private readonly options;
constructor(options: AnthropicProviderOptions);
/**
* Generate response using UniversalMessage
*/
chat(messages: UniversalMessage[], options?: ChatOptions): Promise<UniversalMessage>;
/**
* Generate streaming response using UniversalMessage
*/
chatStream(messages: UniversalMessage[], options?: ChatOptions): AsyncIterable<UniversalMessage>;
supportsTools(): boolean;
validateConfig(): boolean;
dispose(): Promise<void>;
/**
* Convert UniversalMessage to Anthropic format
*
* CRITICAL: Anthropic API requires specific content handling:
* - tool_use messages: content MUST be null
* - regular messages: content should be a string
*/
private convertToAnthropicFormat;
/**
* Convert Anthropic response to UniversalMessage
*/
private convertFromAnthropicResponse;
/**
* Convert tools to Anthropic format
*/
private convertToolsToAnthropicFormat;
/**
* Validate UniversalMessage array
*/
protected validateMessages(messages: UniversalMessage[]): void;
}
/**
* @robota-sdk/anthropic package
*
* Provides Provider implementation for using Anthropic API with provider-agnostic UniversalMessage.
*/
declare function createAnthropicProvider(_options: AnthropicProviderOptions): void;
export { AnthropicProvider, type AnthropicProviderOptions, type ProviderOptionValue, type ProviderOptions, createAnthropicProvider };