/** * Anthropic Computer Use Adapter * * Integrates Anthropic's Computer Use API (Claude with screen/keyboard/mouse * tool use) with the SwarmOrchestrator. * * This adapter wraps the Anthropic Messages API with computer_use tool * definitions, executing multi-step tool-use loops where Claude controls * a virtual desktop via user-supplied action handlers. * * Usage: * const adapter = new AnthropicComputerUseAdapter(); * adapter.registerAgent('browser-agent', { * model: 'claude-sonnet-4-20250514', * client: anthropicInstance, * actionHandler: myScreenHandler, * }); * * @module AnthropicComputerUseAdapter * @version 1.0.0 */ import { BaseAdapter } from './base-adapter'; import type { AdapterCapabilities, AgentPayload, AgentContext, AgentResult } from '../types/agent-adapter'; /** Anthropic tool use action types */ export type ComputerAction = 'screenshot' | 'click' | 'double_click' | 'type' | 'key' | 'scroll' | 'move' | 'drag' | 'wait'; /** A tool use request from Claude */ export interface ComputerToolCall { /** Tool use ID from the API */ toolUseId: string; /** Action to perform */ action: ComputerAction; /** Coordinates for click/move/drag */ coordinate?: [number, number]; /** End coordinates for drag */ endCoordinate?: [number, number]; /** Text for type action */ text?: string; /** Key combination for key action */ key?: string; /** Scroll direction and amount */ scrollDelta?: { x: number; y: number; }; /** Wait duration in ms */ waitMs?: number; } /** Result from executing a tool call */ export interface ComputerToolResult { /** Base64-encoded screenshot after action */ screenshot?: string; /** Text content if applicable */ text?: string; /** Whether the action succeeded */ success: boolean; /** Error message if failed */ error?: string; } /** * User-supplied handler that executes computer actions. * Receives a tool call and returns the result (typically a screenshot). */ export type ComputerActionHandler = (call: ComputerToolCall) => Promise; /** * Minimal interface for the Anthropic SDK messages endpoint. * Compatible with `new Anthropic().messages`. */ export interface AnthropicMessagesClient { create(params: { model: string; max_tokens: number; system?: string; messages: Array<{ role: string; content: unknown; }>; tools?: Array>; }): Promise<{ id: string; content: Array<{ type: string; text?: string; id?: string; name?: string; input?: Record; }>; stop_reason: string | null; usage?: { input_tokens: number; output_tokens: number; }; }>; } /** Configuration for a registered computer-use agent */ export interface ComputerUseAgentConfig { /** Anthropic model (default: 'claude-sonnet-4-20250514') */ model?: string; /** The Anthropic messages client instance */ client: AnthropicMessagesClient; /** Handler that executes computer actions */ actionHandler: ComputerActionHandler; /** System prompt for the agent */ systemPrompt?: string; /** Maximum tool-use loop iterations (default: 20) */ maxIterations?: number; /** Max tokens per API call (default: 4096) */ maxTokens?: number; /** Screen dimensions for the computer_use tool */ screenSize?: { width: number; height: number; }; } /** * Adapter for Anthropic Computer Use (Claude controlling a virtual desktop). * * Runs a tool-use loop: send prompt → Claude returns tool calls → * execute via actionHandler → send results back → repeat until done. */ export declare class AnthropicComputerUseAdapter extends BaseAdapter { readonly name = "anthropic-computer-use"; readonly version = "1.0.0"; private agents; get capabilities(): AdapterCapabilities; /** * Register an agent that uses Anthropic Computer Use. */ registerComputerAgent(agentId: string, config: ComputerUseAgentConfig): void; executeAgent(agentId: string, payload: AgentPayload, _context: AgentContext): Promise; shutdown(): Promise; } //# sourceMappingURL=anthropic-computer-use-adapter.d.ts.map