import { type AgentLoopFrameworkInput, type AgentLoopPolicyOptions, type AgentToolPermissionDecision, type ThinkingLevel } from "@catui/agent-core"; import type { Model } from "@catui/ai/types"; import { AgentSession } from "./agent-session.js"; import type { Theme as ThemeContract } from "../theme-contract.js"; import { AuthStorage } from "../platform/config/auth-storage.js"; import type { LoadExtensionsResult, ToolDefinition } from "../extensions-host/index.js"; import { ModelRegistry } from "../model-registry.js"; import type { ResourceLoader } from "../platform/config/resource-loader.js"; import { SessionManager } from "../session/session-manager.js"; import { SettingsManager } from "../platform/config/settings-manager.js"; import { AgentDirContext } from "../agent-dir/agent-dir-context.js"; import type { SoulOptionsContract } from "../soul-options-contract.js"; import { allTools, bashTool, codingTools, createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, editTool, findTool, grepTool, lsTool, readOnlyTools, readTool, type Tool, writeTool } from "../tools/index.js"; /** * Custom logger interface for SDK users. * Replace console.error/warn/info with user-provided handlers. */ export interface SDKLogger { error(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; } /** * Silent logger - suppresses all output */ export declare const silentLogger: SDKLogger; /** * Default logger - uses console */ export declare const defaultLogger: SDKLogger; export interface CreateAgentSessionOptions extends SoulOptionsContract { /** Working directory for project-local discovery. Default: process.cwd() */ cwd?: string; /** Global config directory. Default: ~/.catui/agents/default */ agentDir?: string; /** Multi-agent context. */ agentCtx?: AgentDirContext; /** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */ authStorage?: AuthStorage; /** Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json) */ modelRegistry?: ModelRegistry; /** Model to use. Default: from settings, else first available */ model?: Model; /** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */ thinkingLevel?: ThinkingLevel; /** Session-level agent loop framework override. Default: from settings/model. */ agentLoopFramework?: AgentLoopFrameworkInput; /** Optional runtime loop policy overrides applied at session creation. */ loopPolicy?: Pick; /** Maximum assistant turns allowed for one prompt. */ maxTurnsPerPrompt?: number; /** Maximum tool calls allowed for one prompt. */ maxToolCallsPerPrompt?: number; /** Maximum concurrent safe tool calls in compatible loops. */ maxToolConcurrency?: number; /** Aggregate tool-result batch budget in characters. */ maxToolResultBatchSizeChars?: number; /** Optional target for automatic continuation when output is under-complete. */ outputTokenBudget?: AgentLoopPolicyOptions["outputTokenBudget"]; /** Maximum automatic output-token recovery turns per prompt. */ maxOutputTokenRecoveryAttempts?: number; /** Maximum in-loop model error recoveries per prompt. */ maxModelErrorRecoveryAttempts?: number; /** Maximum stop-hook validation/correction continuations per prompt. */ maxStopHookContinuations?: number; /** Models available for cycling (Ctrl+P in interactive mode) */ scopedModels?: Array<{ model: Model; thinkingLevel: ThinkingLevel; }>; /** Built-in tools to use. Default: codingTools [read, bash, edit, write] */ tools?: Tool[]; /** Custom tools to register (in addition to built-in tools). */ customTools?: ToolDefinition[]; /** Enable MCP (Model Context Protocol) tools. Default: false */ enableMCP?: boolean; /** * Defer MCP tool loading off the startup critical path. When true, * createAgentSession does NOT block on MCP server spawn/handshake; the caller * must call `session.warmupMcpTools()` (interactive mode does this in the * background once the UI is ready). When false/omitted, MCP is loaded * synchronously before returning (one-shot modes: print/acp/rpc). Default: false */ deferMcpInit?: boolean; /** Resource loader. When omitted, DefaultResourceLoader is used. */ resourceLoader?: ResourceLoader; /** Additional directories to search for skills. Appended to default paths. */ additionalSkillPaths?: string[]; /** Additional directories to search for AGENT.md/CLAUDE.md context files. */ additionalAgentDirs?: string[]; /** Additional extension paths to load (merged with built-in extensions). */ additionalExtensionPaths?: string[]; /** Custom MCP config file path. Overrides default agentDir/mcp.json. */ mcpConfigPath?: string; /** Debug event verbosity level. "off" = none, "basic" = lifecycle, "verbose" = all. Default: "off" */ debugLevel?: "off" | "basic" | "verbose"; /** * Permission mode for the session. * * - `'agent'` (default): all tools available, full execution capability. * - `'plan'`: restricted mode — only read-only tools and .md file writes allowed. * Blocks Bash (except read-only commands), Edit, and other mutating tools. * Useful for GUI consumers implementing a "plan before execute" workflow. */ permissionMode?: "plan" | "agent"; /** * Optional tool permission gate for intercepting tool calls before execution. * * Called after schema validation and before the tool executes. * Return `{ decision: "allow" }` to proceed, or `{ decision: "deny", reason }` to block. * Useful for GUI consumers that want to intercept tools like AskUserQuestion * and handle them in their own UI layer. */ canUseTool?: (event: { toolCallId: string; toolName: string; requestedToolName: string; input: unknown; rawInput: unknown; }) => Promise | AgentToolPermissionDecision; /** * Tool whitelist. When specified, only these tools are allowed to execute. * All other tools will be denied. Useful for constraining the agent to a * specific set of capabilities. * * Applied BEFORE `canUseTool` — if a tool is not in `allowedTools`, it is * denied without calling `canUseTool`. */ allowedTools?: string[]; /** * Tool blacklist. When specified, these tools are always denied. * Useful for disabling specific tools without restricting everything else. * * Applied BEFORE `canUseTool` — if a tool is in `disallowedTools`, it is * denied without calling `canUseTool`. */ disallowedTools?: string[]; /** * Custom system prompt. Two forms: * * - `string`: Appended to the agent's base system prompt as-is. * - `{ type: 'preset', preset: string, append?: string }`: Uses the named * preset as the base prompt, then appends `append` if provided. * In catui-agent, the default base prompt is always used; `preset` is * accepted for API compatibility but does not change the base prompt. */ systemPrompt?: string | { type: "preset"; preset: string; append?: string; }; /** * Token budgets for each thinking level. Overrides settings-level defaults. * Maps thinking level names to max token counts for extended thinking. */ thinkingBudgets?: { minimal?: number; low?: number; medium?: number; high?: number; }; /** * Additional environment variables to merge into the agent's process environment. * Applied at session creation; child processes inherit these. */ env?: Record; /** Session manager. Default: SessionManager.create(cwd) */ sessionManager?: SessionManager; /** Settings manager. Default: SettingsManager.create(cwd, agentDir) */ settingsManager?: SettingsManager; /** External abort signal for stopping the session (e.g., from SubAgent runtime) */ signal?: AbortSignal; /** * Theme for HTML-export custom-tool rendering. Provided by the composition root * (UI layer); when omitted, HTML export skips custom-tool rendering. Keeps * core/runtime free of a modes/ UI import (U2 seam). */ theme?: ThemeContract; /** Suppress all console output. Default: false */ silent?: boolean; /** Custom logger for SDK output. Default: console */ logger?: SDKLogger; } /** Result from createAgentSession */ export interface CreateAgentSessionResult { /** The created session */ session: AgentSession; /** Extensions result (for UI context setup in interactive mode) */ extensionsResult: LoadExtensionsResult; /** Warning if session was restored with a different model than saved */ modelFallbackMessage?: string; /** Soul manager for AI personality (if enabled) */ soulManager?: any; } export type { ExtensionAPI, ExtensionCommandContext, ExtensionContext, ExtensionFactory, SlashCommandInfo, SlashCommandLocation, SlashCommandSource, ToolDefinition, } from "../extensions-host/index.js"; export type { AgentToolPermissionDecision } from "@catui/agent-core"; export type { PromptTemplate } from "../prompt/prompt-templates.js"; export type { Skill } from "../skills.js"; export type { Tool } from "../tools/index.js"; export { readTool, bashTool, editTool, writeTool, grepTool, findTool, lsTool, codingTools, readOnlyTools, allTools as allBuiltInTools, createCodingTools, createReadOnlyTools, createReadTool, createBashTool, createEditTool, createWriteTool, createGrepTool, createFindTool, createLsTool, }; export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise;