/** * [WHO]: CatuiAgent - Simplified SDK wrapper for better DX * [FROM]: Depends on sdk.ts, agent-session.ts, tools/index.ts * [TO]: Consumed by index.ts, external SDK users * [HERE]: core/runtime/catui-agent.ts - high-level wrapper class with simplified API */ import { type SDKLogger } from "./sdk.js"; import { type AgentSessionEvent } from "./agent-session.js"; import type { Api } from "@catui/ai/types"; import type { ThinkingLevel } from "@catui/agent-core"; /** * Simplified options for CatuiAgent wrapper. */ export interface CatuiAgentOptions { /** API key for the provider. If omitted, uses environment variable. */ apiKey?: string; /** Provider name: 'anthropic', 'openai', 'google', or any custom provider in models.json. */ provider?: string; /** Model ID: 'claude-4-5-20250920', 'gpt-4o', etc. */ model?: string; /** * Optional base URL when registering a custom provider on the fly. * Required when `provider` + `model` is not already defined in * ~/.catui/agents/default/models.json. Ignored when the model is found. */ baseUrl?: string; /** * Optional API protocol for the dynamically-registered provider. * Defaults to "openai-completions". Ignored when the model is found. */ api?: Api; /** Thinking level: 'off' | 'low' | 'medium' | 'high' */ thinkingLevel?: ThinkingLevel; /** Working directory. Default: process.cwd() */ cwd?: string; /** Initial tool names: ['read', 'bash', 'edit', 'write'] */ tools?: string[]; /** Enable MCP tools */ enableMCP?: boolean; /** Enable Soul personality */ enableSoul?: boolean; /** Suppress all console output */ silent?: boolean; /** Custom logger */ logger?: SDKLogger; /** In-memory session (no persistence) */ inMemory?: boolean; /** Abort signal for external control */ signal?: AbortSignal; } /** * Simplified wrapper for Catui SDK. * * @example * ```typescript * // Minimal usage * const agent = new CatuiAgent(); * await agent.init(); * const result = await agent.run('Hello'); * * // With explicit config * const agent = new CatuiAgent({ * apiKey: 'sk-xxx', * silent: true, * }); * await agent.init(); * ``` */ export declare class CatuiAgent { private session; private sessionResult; private logger; private options; private cwd; private initialized; private collectedText; private eventListeners; constructor(options?: CatuiAgentOptions); /** * Initialize the agent session. * Must be called before run/chat. */ init(): Promise; /** * Resolve constructor-provided provider/model into a Model. * * Lookup order: * 1. Existing entry in modelRegistry (e.g. ~/.catui/agents/default/models.json * already declares this provider/model — common case for users who ran * /sal:setup or hand-edited models.json). * 2. Dynamic registration when caller supplied baseUrl + apiKey — lets a * one-line constructor call wire up a brand-new OpenAI-compatible * endpoint without touching disk. * 3. Otherwise return undefined and let createAgentSession fall back to * findInitialModel() (built-in default). The logger surfaces a warning * in this case so the caller knows their args were not honoured. */ private resolveRequestedModel; /** * Handle session events - collects text for run() */ private handleEvent; /** * Ensure session is initialized. */ private ensureInit; /** * Run a complete task - returns final result. * Blocks until agent finishes all tool calls. * * @example * ```typescript * await agent.init(); * const result = await agent.run('Read README.md and summarize'); * ``` */ run(message: string): Promise; /** * Send a prompt and collect events. * * @example * ```typescript * await agent.init(); * agent.subscribe((event) => { * if (event.type === 'tool_call') { * console.log('Tool:', event.name); * } * }); * await agent.prompt('Hello'); * ``` */ prompt(message: string): Promise; /** * Reset the session (clear conversation history, start a new session). */ reset(): Promise; /** * Shutdown the session. */ shutdown(): Promise; /** * Subscribe to agent events. * * @example * ```typescript * await agent.init(); * agent.subscribe((event) => { * if (event.type === 'sdk:error') { * console.error('SDK error:', event.error); * } * }); * ``` */ subscribe(listener: (event: AgentSessionEvent) => void): void; /** * Remove event subscription. */ unsubscribe(listener: (event: AgentSessionEvent) => void): void; /** * Check if agent is initialized. */ isInitialized(): boolean; /** * Get last collected text. */ getLastText(): string; } /** * Quick factory for CatuiAgent with auto-init. * * @example * ```typescript * const agent = await quickAgent({ apiKey: 'sk-xxx' }); * ``` */ export declare function quickAgent(options?: CatuiAgentOptions): Promise; /** * Legacy compatibility alias for SDK users migrating from the Pencil brand. * New code should import CatuiAgent/CatuiAgentOptions from @catui/agent. */ export { CatuiAgent as PencilAgent }; export type { CatuiAgentOptions as PencilAgentOptions };