Skip to main content

synth_ai_core/
lib.rs

1//! Synth core library.
2//!
3//! This crate provides the core functionality for the Synth SDK:
4//! - API client for backend communication
5//! - Authentication and credential management
6//! - Configuration handling
7//! - HTTP client utilities
8//! - Job orchestration and streaming
9//! - Tracing and storage
10//! - Tunnel management
11//! - Data types (enums, rubrics, objectives, etc.)
12//! - Streaming framework
13//! - Local API client for task apps
14
15pub mod api;
16pub mod auth;
17pub mod config;
18pub mod data;
19pub mod errors;
20pub mod events;
21pub mod http;
22pub mod jobs;
23pub mod localapi;
24pub mod models;
25pub mod orchestration;
26pub mod polling;
27pub mod shared_client;
28pub mod sse;
29pub mod streaming;
30pub mod trace_upload;
31pub mod tracing;
32pub mod tunnels;
33pub mod urls;
34pub mod utils;
35
36// Re-export core types at crate root for convenience
37pub use errors::{CoreError, CoreResult, HttpErrorInfo, JobErrorInfo, UsageLimitInfo};
38pub use jobs::{CandidateStatus, JobEvent, JobEventType, JobLifecycle, JobStatus};
39
40// Re-export API types for convenience
41pub use api::{
42    EvalJobStatus, GraphEvolveClient, InferenceClient, LocalApiDeployClient,
43    LocalApiDeployResponse, LocalApiDeploySpec, LocalApiDeployStatus, LocalApiDeploymentInfo,
44    LocalApiLimits, PolicyJobStatus, SynthClient,
45};
46
47// Re-export model helpers
48pub use models::{detect_model_provider, normalize_model_identifier, supported_models};
49
50// Re-export orchestration types
51pub use orchestration::{
52    base_event_schemas, base_job_event_schema, build_graph_evolve_config,
53    build_graph_evolve_graph_record_payload, build_graph_evolve_inference_payload,
54    build_graph_evolve_payload, build_graph_evolve_placeholder_dataset, build_program_candidate,
55    build_prompt_learning_payload, convert_openai_sft, event_enum_values,
56    extract_program_candidate_content, extract_stages_from_candidate, get_base_schema,
57    graph_opt_supported_models, is_valid_event_type, load_graph_evolve_dataset,
58    load_graph_job_toml, load_graphgen_taskset, merge_event_schema,
59    normalize_graph_evolve_policy_models, normalize_transformation, parse_graph_evolve_dataset,
60    parse_graphgen_taskset, resolve_graph_evolve_snapshot_id, seed_reward_entry, seed_score_entry,
61    validate_event_type, validate_graph_job_payload, validate_graph_job_section,
62    validate_graphgen_job_config, validate_graphgen_taskset, validate_prompt_learning_config,
63    validate_prompt_learning_config_strict, CandidateInfo, EventCategory, EventParser, EventStream,
64    GEPAProgress, GraphEvolveJob, GraphGenValidationResult, MutationSummary, MutationTypeStats,
65    ParsedEvent, PhaseSummary, ProgramCandidate, ProgressTracker, PromptLearningJob,
66    PromptLearningResult, PromptLearningValidationResult, PromptResults, RankedPrompt,
67    SeedAnalysis, SeedInfo, StageInfo, TokenUsage, MAX_INSTRUCTION_LENGTH, MAX_ROLLOUT_SAMPLES,
68    MAX_SEED_INFO_COUNT,
69};
70
71// Re-export tracing types
72pub use tracing::{
73    BaseEventFields, EnvironmentEvent, EventReward, EventType, HookCallback, HookContext,
74    HookEvent, HookManager, LLMCallRecord, LLMContentPart, LLMMessage, LLMUsage, LMCAISEvent,
75    MarkovBlanketMessage, MessageContent, OutcomeReward, RuntimeEvent,
76    SessionTimeStep, SessionTrace, SessionTracer, StorageConfig, TimeRecord, ToolCallResult,
77    ToolCallSpec, TraceStorage, TracingError, TracingEvent,
78};
79
80#[cfg(feature = "libsql")]
81pub use tracing::LibsqlTraceStorage;
82
83// Re-export data types
84pub use data::{
85    // Enum values mapping
86    data_enum_values,
87    AdaptiveBatchLevel,
88    AdaptiveCurriculumLevel,
89    ApplicationErrorType,
90    ApplicationStatus,
91    // Artifacts
92    Artifact,
93    ArtifactBundle,
94    ArtifactContent,
95    // Context overrides
96    ContextOverride,
97    ContextOverrideStatus,
98    Criterion,
99    CriterionScoreData,
100    EventObjectiveAssignment,
101    GraphType,
102    InferenceMode,
103    JobStatus as DataJobStatus,
104    // Enums
105    JobType,
106    // Judgements
107    Judgement,
108    ObjectiveDirection,
109    ObjectiveKey,
110    // Objectives
111    ObjectiveSpec,
112    OptimizationMode,
113    OutcomeObjectiveAssignment,
114    OutputMode,
115    ProviderName,
116    RewardObservation,
117    RewardScope,
118    RewardSource,
119    RewardType,
120    // Rubrics
121    Rubric,
122    RubricAssignment,
123    SuccessStatus,
124    TrainingType,
125    VerifierMode,
126};
127
128// Re-export streaming types
129pub use streaming::{
130    BufferedHandler, CallbackHandler, JobStreamer, JsonHandler, MultiHandler, StreamConfig,
131    StreamEndpoints, StreamHandler, StreamMessage, StreamType,
132};
133
134// Re-export SSE helpers
135pub use sse::{stream_sse, stream_sse_request, SseEvent, SseStream};
136
137// Re-export local API types
138pub use localapi::{
139    allowed_environment_api_keys, apply_context_overrides, build_rollout_response,
140    build_trace_payload, build_trajectory_trace, encrypt_for_backend, ensure_localapi_auth,
141    ensure_split, extract_api_key, extract_message_text, extract_trace_correlation_id,
142    get_agent_skills_path, get_applied_env_vars, get_default_max_completion_tokens, get_groq_key,
143    get_openai_key, include_event_history_in_response, include_event_history_in_trajectories,
144    include_trace_correlation_id_in_response, inject_system_hint, is_api_key_header_authorized,
145    is_direct_provider_call, mint_environment_api_key, normalise_seed,
146    normalize_chat_completion_url, normalize_environment_api_key, normalize_inference_url,
147    normalize_response_format_for_groq, normalize_vendor_keys, parse_tool_call_from_text,
148    parse_tool_calls_from_response, prepare_for_groq, prepare_for_openai, resolve_sft_output_dir,
149    resolve_tracing_db_url, setup_environment_api_key, synthesize_tool_call_if_missing,
150    task_app_health, tracing_env_enabled, unique_sft_path, validate_artifact_size,
151    validate_artifacts_list, validate_context_overrides, validate_context_snapshot,
152    validate_rollout_response_for_rl, validate_task_app_url, validate_trace_correlation_id,
153    verify_trace_correlation_id_in_response, DatasetInfo, HealthResponse, InferenceInfo,
154    InfoResponse, LimitsInfo, RolloutEnvSpec, RolloutMetrics, RolloutPolicySpec, RolloutRequest,
155    RolloutResponse, RolloutSafetyConfig, TaskAppClient, TaskDatasetSpec, TaskDescriptor, TaskInfo,
156    DEV_ENVIRONMENT_API_KEY_NAME, ENVIRONMENT_API_KEY_ALIASES_NAME, ENVIRONMENT_API_KEY_NAME,
157    MAX_ARTIFACTS_PER_ROLLOUT, MAX_ARTIFACT_CONTENT_TYPE_LENGTH, MAX_ARTIFACT_METADATA_BYTES,
158    MAX_CONTEXT_OVERRIDES_PER_ROLLOUT, MAX_CONTEXT_SNAPSHOT_BYTES, MAX_ENVIRONMENT_API_KEY_BYTES,
159    MAX_ENV_VARS, MAX_ENV_VAR_VALUE_LENGTH, MAX_FILES_PER_OVERRIDE, MAX_FILE_SIZE_BYTES,
160    MAX_INLINE_ARTIFACT_BYTES, MAX_TOTAL_INLINE_ARTIFACTS_BYTES, MAX_TOTAL_SIZE_BYTES,
161    PREFLIGHT_SCRIPT_TIMEOUT_SECONDS, SEALED_BOX_ALGORITHM,
162};
163
164// Re-export trace upload types
165pub use trace_upload::{TraceUploadClient, UploadUrlResponse};
166
167// Re-export utility helpers
168pub use utils::{
169    cleanup_paths, compute_import_paths, create_and_write_json, ensure_private_dir,
170    find_config_path, get_bin_path, get_home_config_file_paths, is_file_type, is_hidden_path,
171    load_json_to_value, repo_root, should_filter_log_line, strip_json_comments, synth_bin_dir,
172    synth_home_dir, synth_localapi_config_path, synth_user_config_path, validate_file_type,
173    write_private_json, write_private_text,
174};