Skip to main content

ai_agent/
lib.rs

1#![allow(dead_code)]
2#![allow(unused)]
3#![allow(unused_mut)]
4#![allow(unused_variables)]
5#![allow(unexpected_cfgs)]
6#![allow(unreachable_patterns)]
7#![allow(irrefutable_let_patterns)]
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10#![allow(async_fn_in_trait)]
11
12pub mod agent;
13pub mod engine;
14pub mod error;
15pub mod hooks;
16pub mod http_client;
17pub mod mcp;
18pub mod message_queue_types;
19pub mod session;
20pub mod state;
21pub mod task;
22pub mod tool_helper;
23pub mod tools;
24pub mod types;
25pub mod utils;
26
27pub mod env;
28pub mod extract_memories;
29pub mod memory;
30pub mod permission;
31pub mod plugin;
32
33pub use utils::{
34    create_abort_controller, create_abort_controller_default, create_agent_id,
35    create_child_abort_controller, get_aws_region, get_claude_config_home_dir, get_cwd,
36    get_default_vertex_region, get_original_cwd, get_teams_dir, get_vertex_region_for_model,
37    has_node_option, is_bare_mode, is_env_defined_falsy, is_env_truthy, is_in_protected_namespace,
38    is_running_on_homespace, parse_env_vars, pwd, run_with_cwd_override, set_cwd,
39    should_maintain_project_working_dir, validate_uuid, AbortController, AbortSignal, AgentId,
40};
41pub mod ai_md;
42pub mod analytics;
43pub mod bridge;
44pub mod bridge_enabled;
45pub mod commands;
46pub mod compact;
47pub mod constants;
48pub mod coordinator;
49pub mod cost;
50pub mod memory_types;
51pub mod prompts;
52pub mod query_engine;
53pub mod review;
54pub mod services;
55pub mod session_discovery;
56pub mod session_history;
57pub mod session_memory;
58pub mod skills;
59pub mod team_memory;
60pub mod user_agent;
61
62pub use agent::Agent;
63pub use ai_md::{
64    get_ai_md_files, load_ai_md, process_ai_md_file, AiMdContent, AiMdFile, AiMdType,
65    AI_MD_INSTRUCTION_PROMPT, MAX_AI_MD_CHARACTER_COUNT,
66};
67pub use bridge_enabled::{
68    check_bridge_min_version, get_bridge_disabled_reason, get_ccr_auto_connect_default,
69    is_bridge_enabled, is_bridge_enabled_blocking, is_ccr_mirror_enabled, is_cse_shim_enabled,
70    is_env_less_bridge_enabled, OauthAccountInfo,
71};
72pub use compact::{
73    compact_errors, estimate_token_count, get_compact_command, get_effective_context_window_size,
74    get_auto_compact_threshold, should_compact, calculate_token_warning_state, CompactCommand,
75    TokenWarningState, AUTOCOMPACT_BUFFER_TOKENS, WARNING_THRESHOLD_BUFFER_TOKENS,
76    ERROR_THRESHOLD_BUFFER_TOKENS, MANUAL_COMPACT_BUFFER_TOKENS, MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES,
77};
78pub use services::compact::auto_compact::{
79    is_auto_compact_enabled, should_auto_compact, AutoCompactTrackingState, AutoCompactResult,
80    RecompactionInfo,
81};
82pub use engine::QueryEngine;
83pub use env::{is_assistant_mode, is_assistant_mode_enabled, EnvConfig};
84pub use error::AgentError;
85pub use extract_memories::{
86    build_extract_auto_only_prompt, build_extract_combined_prompt,
87    count_model_visible_messages_since, count_tool_calls, create_auto_mem_can_use_tool,
88    drain_pending_extractions, execute_extract_memories, parse_extracted_content,
89    should_extract_memories, ExtractMemoriesConfig, ExtractMemoriesResult, ExtractMemoriesState,
90    MemoryEntry, MemoryEntryType, PendingExtraction,
91};
92pub use hooks::{
93    create_hook_registry, HookConfig, HookDefinition, HookInput, HookOutput, HookRegistry,
94    CONFIG_CHANGE_SOURCES, EXIT_REASONS, HOOK_EVENTS, INSTRUCTIONS_LOAD_REASONS,
95    INSTRUCTIONS_MEMORY_TYPES,
96};
97pub use memory::{
98    ensure_memory_dir_exists, get_auto_mem_path, get_memory_base_dir, get_memory_entrypoint,
99    get_project_slug, is_auto_mem_path, is_auto_memory_enabled, load_memory_prompt,
100    EntrypointTruncation, MemoryFrontmatter, MemoryType, MAX_ENTRYPOINT_LINES,
101};
102pub use message_queue_types::MessageQueueEntry;
103pub use permission::{
104    PermissionAllowDecision, PermissionAskDecision, PermissionBehavior, PermissionContext,
105    PermissionDecision, PermissionDecisionReason, PermissionDenyDecision, PermissionHandler,
106    PermissionMetadata, PermissionMode, PermissionResult, PermissionRule, PermissionRuleSource,
107};
108pub use plugin::{
109    get_plugin_error_message, load_plugin, load_plugin_skills, load_plugins_from_dir,
110    load_plugins_from_sources, register_plugin_skills, CommandAvailability, CommandMetadata,
111    CommandRegistry, CommandResult, CommandResultDisplay, CommandSource, LoadedPlugin,
112    PluginAuthor, PluginCommand, PluginComponent, PluginConfig, PluginError, PluginLoadResult,
113    PluginManifest, PluginMcpServer, PluginMcpServerManager, PluginRepository, PluginSkill,
114};
115pub use services::{
116    api::{
117        categorize_retryable_api_error, classify_api_error, create_assistant_api_error_message,
118        create_assistant_api_error_message_with_options, extract_unknown_error_format,
119        get_error_message_if_refusal, get_image_too_large_error_message,
120        get_oauth_org_not_allowed_error_message, get_pdf_invalid_error_message,
121        get_pdf_password_protected_error_message, get_pdf_too_large_error_message,
122        get_prompt_too_long_token_gap, get_request_too_large_error_message,
123        get_token_revoked_error_message, is_ccr_mode, is_media_size_error,
124        is_media_size_error_message, is_prompt_too_long_message, is_valid_api_message,
125        parse_prompt_too_long_token_counts, starts_with_api_error_prefix, ApiErrorMessage,
126        ApiErrorType, SDKAssistantMessageError, API_ERROR_MESSAGE_PREFIX,
127        API_TIMEOUT_ERROR_MESSAGE, CCR_AUTH_ERROR_MESSAGE, CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE,
128        CUSTOM_OFF_SWITCH_MESSAGE, INVALID_API_KEY_ERROR_MESSAGE,
129        INVALID_API_KEY_ERROR_MESSAGE_EXTERNAL, NO_RESPONSE_REQUESTED,
130        OAUTH_ORG_NOT_ALLOWED_ERROR_MESSAGE, ORG_DISABLED_ERROR_MESSAGE_ENV_KEY,
131        ORG_DISABLED_ERROR_MESSAGE_ENV_KEY_WITH_OAUTH, PROMPT_TOO_LONG_ERROR_MESSAGE,
132        REPEATED_529_ERROR_MESSAGE, TOKEN_REVOKED_ERROR_MESSAGE,
133    },
134    model_cost::{
135        calculate_cost, format_cost, get_available_models, CostSummary, ModelCostRegistry,
136        ModelCosts, ModelInfo, TokenUsage, COST_HAIKU_35, COST_HAIKU_45, COST_TIER_15_75,
137        COST_TIER_3_15, COST_TIER_5_25,
138    },
139    rate_limit::{
140        RateLimit as RateLimitInfo, RateLimitConfig, RateLimitStatus, RateLimiter,
141        RateLimiterBuilder,
142    },
143    retry::{
144        is_rate_limit_error, is_retryable_error, is_service_unavailable_error, retry_async,
145        retry_with_retry_after, RetryConfig, RetryError, DEFAULT_MAX_RETRIES,
146    },
147    token_estimation::{
148        calculate_padding, estimate_conversation, estimate_tokens, estimate_tokens_characters,
149        estimate_tokens_words, estimate_tool_definitions, fits_in_context, EstimationMethod,
150        TokenEstimate,
151    },
152};
153pub use session::{
154    append_to_session, delete_session, fork_session, get_session_info, get_session_messages,
155    list_sessions, load_session, rename_session, save_session, tag_session, SessionData,
156    SessionMetadata,
157};
158pub use session_discovery::discover_assistant_sessions;
159pub use session_history::{
160    create_history_auth_ctx, fetch_latest_events, fetch_older_events, get_bridge_access_token,
161    get_bridge_base_url, get_bridge_base_url_override, get_bridge_headers,
162    get_bridge_token_override, get_oauth_headers, prepare_api_request, HistoryAuthCtx, HistoryPage,
163    OAuthTokens, OauthConfig, SDKMessage, HISTORY_PAGE_SIZE,
164};
165pub use session_memory::{
166    get_last_summarized_message_id, get_session_memory_config, get_session_memory_content,
167    get_session_memory_dir, get_session_memory_path, get_session_memory_state,
168    get_tool_calls_between_updates, has_met_initialization_threshold, has_met_update_threshold,
169    init_session_memory_file, is_session_memory_initialized, mark_session_memory_initialized,
170    record_extraction_token_count, reset_session_memory_state, set_last_summarized_message_id,
171    set_session_memory_config, should_extract_memory, wait_for_session_memory_extraction,
172    ManualExtractionResult, SessionMemoryConfig, SessionMemoryState, DEFAULT_SESSION_MEMORY_CONFIG,
173};
174pub use skills::{
175    get_bundled_skills, init_bundled_skills, load_skill_from_dir, load_skills_from_dir,
176    BundledSkill, LoadedSkill, SkillMetadata,
177};
178pub use state::Store;
179pub use task::{
180    create_task_state_base, generate_task_id, get_task_id_prefix, get_task_output_path,
181    is_terminal_task_status, LocalShellSpawnInput, ShellKind, TaskHandle, TaskStateBase,
182    TaskStatus, TaskType, TASK_ID_ALPHABET, TASK_ID_PREFIXES,
183};
184pub use team_memory::{
185    batch_delta_by_bytes, compute_delta, create_sync_state, delete_local_team_memory_entry,
186    disable_team_memory, enable_team_memory, get_last_sync_error, get_team_memory_dir,
187    get_team_memory_path, hash_content, is_team_memory_enabled, is_team_memory_sync_available,
188    pull_team_memory, push_team_memory, read_local_team_memory, scan_entries_for_secrets,
189    scan_for_secrets, set_last_sync_error, sync_team_memory, validate_team_memory_key,
190    write_local_team_memory, SkippedSecretFile, SyncState, TeamMemoryContent, TeamMemoryData,
191    TeamMemoryHashesResult, TeamMemorySyncFetchResult, TeamMemorySyncPushResult,
192    TeamMemorySyncUploadResult, TeamMemoryTooManyEntries, MAX_CONFLICT_RETRIES,
193    MAX_FILE_SIZE_BYTES, MAX_PUT_BODY_BYTES, MAX_RETRIES, TEAM_MEMORY_SYNC_TIMEOUT_MS,
194};
195pub use tool_helper::{
196    create_tool, create_tool_with_annotations, sdk_tool_to_tool_definition, SdkToolDefinition,
197    ToolAnnotations,
198};
199pub use tools::{filter_tools, get_all_base_tools, Tool, ToolDefinition, ToolInputSchema, ToolFuture};
200pub use types::*;
201
202/// Create a new agent with the given model and max turns.
203/// This is a convenience function that matches the TypeScript SDK API.
204/// Create a new agent (alias for Agent::new)
205pub fn create_agent(model: &str, max_turns: u32) -> Agent {
206    Agent::new(model, max_turns)
207}
208
209/// Alias for get_all_base_tools to match TypeScript API
210pub fn get_all_tools() -> Vec<ToolDefinition> {
211    get_all_base_tools()
212}
213
214/// Build-time version constant (matches TypeScript MACRO.VERSION)
215pub const MACRO_VERSION: &str = env!("CARGO_PKG_VERSION");
216
217pub use user_agent::get_claude_code_user_agent;
218
219// Re-export coordinator utilities
220pub use coordinator::{
221    get_coordinator_system_prompt, get_coordinator_user_context, is_coordinator_mode,
222    match_session_mode, WORKER_AGENT,
223};