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 containers
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 container;
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;
35pub mod x402;
36
37// Re-export core types at crate root for convenience
38pub use errors::{CoreError, CoreResult, HttpErrorInfo, JobErrorInfo, UsageLimitInfo};
39pub use jobs::{CandidateStatus, JobEvent, JobEventType, JobLifecycle, JobStatus};
40
41// Re-export API types for convenience
42pub use api::{
43    EvalJobStatus, GraphEvolveClient, InferenceClient, ContainerDeployClient,
44    ContainerDeployResponse, ContainerDeploySpec, ContainerDeployStatus, ContainerDeploymentInfo,
45    ContainerLimits, PolicyJobStatus, SynthClient,
46};
47
48// Re-export model helpers
49pub use models::{detect_model_provider, normalize_model_identifier, supported_models};
50
51// Re-export orchestration types
52pub use orchestration::{
53    base_event_schemas, base_job_event_schema, build_graph_evolve_config,
54    build_graph_evolve_graph_record_payload, build_graph_evolve_inference_payload,
55    build_graph_evolve_payload, build_graph_evolve_placeholder_dataset, build_program_candidate,
56    build_prompt_learning_payload, convert_openai_sft, event_enum_values,
57    extract_program_candidate_content, extract_stages_from_candidate, get_base_schema,
58    graph_opt_supported_models, is_valid_event_type, load_graph_evolve_dataset,
59    load_graph_job_toml, load_graphgen_taskset, merge_event_schema,
60    normalize_graph_evolve_policy_models, normalize_transformation, parse_graph_evolve_dataset,
61    parse_graphgen_taskset, resolve_graph_evolve_snapshot_id, seed_reward_entry, seed_score_entry,
62    validate_event_type, validate_graph_job_payload, validate_graph_job_section,
63    validate_graphgen_job_config, validate_graphgen_taskset, validate_prompt_learning_config,
64    validate_prompt_learning_config_strict, CandidateInfo, EventCategory, EventParser, EventStream,
65    GEPAProgress, GraphEvolveJob, GraphGenValidationResult, MutationSummary, MutationTypeStats,
66    ParsedEvent, PhaseSummary, ProgramCandidate, ProgressTracker, PromptLearningJob,
67    PromptLearningResult, PromptLearningValidationResult, PromptResults, RankedPrompt,
68    SeedAnalysis, SeedInfo, StageInfo, TokenUsage, MAX_INSTRUCTION_LENGTH, MAX_ROLLOUT_SAMPLES,
69    MAX_SEED_INFO_COUNT,
70};
71
72// Re-export tracing types
73pub use tracing::{
74    BaseEventFields, EnvironmentEvent, EventReward, EventType, HookCallback, HookContext,
75    HookEvent, HookManager, LLMCallRecord, LLMContentPart, LLMMessage, LLMUsage, LMCAISEvent,
76    MarkovBlanketMessage, MessageContent, OutcomeReward, RuntimeEvent, SessionTimeStep,
77    SessionTrace, SessionTracer, StorageConfig, TimeRecord, ToolCallResult, ToolCallSpec,
78    TraceStorage, TracingError, TracingEvent,
79};
80
81#[cfg(feature = "libsql")]
82pub use tracing::LibsqlTraceStorage;
83
84// Re-export data types
85pub use data::{
86    // Enum values mapping
87    data_enum_values,
88    lever_sensor_v1_contract_schema,
89    AdaptiveBatchLevel,
90    AdaptiveCurriculumLevel,
91    ApplicationErrorType,
92    ApplicationStatus,
93    // Artifacts
94    Artifact,
95    ArtifactBundle,
96    ArtifactContent,
97    // Context overrides
98    ContextOverride,
99    ContextOverrideStatus,
100    Criterion,
101    CriterionScoreData,
102    EventObjectiveAssignment,
103    GraphType,
104    InferenceMode,
105    JobStatus as DataJobStatus,
106    // Enums
107    JobType,
108    // Judgements
109    Judgement,
110    // Levers + Sensors
111    Lever,
112    LeverActor,
113    LeverConstraints,
114    LeverFormat,
115    LeverKind,
116    LeverMutability,
117    LeverMutation,
118    LeverProvenance,
119    LeverSnapshot,
120    MiproLeverSummary,
121    ObjectiveDirection,
122    ObjectiveKey,
123    // Objectives
124    ObjectiveSpec,
125    OptimizationMode,
126    OutcomeObjectiveAssignment,
127    OutputMode,
128    ProviderName,
129    RewardObservation,
130    RewardScope,
131    RewardSource,
132    RewardType,
133    // Rubrics
134    Rubric,
135    RubricAssignment,
136    ScopeKey,
137    ScopeKind,
138    Sensor,
139    SensorFrame,
140    SensorFrameSummary,
141    SensorKind,
142    SuccessStatus,
143    TrainingType,
144    VerifierMode,
145};
146
147// Re-export streaming types
148pub use streaming::{
149    BufferedHandler, CallbackHandler, JobStreamer, JsonHandler, MultiHandler, StreamConfig,
150    StreamEndpoints, StreamHandler, StreamMessage, StreamType,
151};
152
153// Re-export SSE helpers
154pub use sse::{stream_sse, stream_sse_request, SseEvent, SseStream};
155
156// Re-export local API types
157pub use container::{
158    allowed_environment_api_keys, apply_context_overrides, build_rollout_response,
159    build_trace_payload, build_trajectory_trace, encrypt_for_backend, ensure_container_auth,
160    ensure_split, extract_api_key, extract_message_text, extract_trace_correlation_id,
161    get_agent_skills_path, get_applied_env_vars, get_default_max_completion_tokens, get_groq_key,
162    get_openai_key, include_event_history_in_response, include_event_history_in_trajectories,
163    include_trace_correlation_id_in_response, inject_system_hint, is_api_key_header_authorized,
164    is_direct_provider_call, mint_environment_api_key, normalise_seed,
165    normalize_chat_completion_url, normalize_environment_api_key, normalize_inference_url,
166    normalize_response_format_for_groq, normalize_vendor_keys, parse_tool_call_from_text,
167    parse_tool_calls_from_response, prepare_for_groq, prepare_for_openai, resolve_sft_output_dir,
168    resolve_tracing_db_url, setup_environment_api_key, synthesize_tool_call_if_missing,
169    container_health, tracing_env_enabled, unique_sft_path, validate_artifact_size,
170    validate_artifacts_list, validate_context_overrides, validate_context_snapshot,
171    validate_rollout_response_for_rl, validate_container_url, validate_trace_correlation_id,
172    verify_trace_correlation_id_in_response, DatasetInfo, HealthResponse, InferenceInfo,
173    InfoResponse, LimitsInfo, RolloutEnvSpec, RolloutMetrics, RolloutPolicySpec, RolloutRequest,
174    RolloutResponse, RolloutSafetyConfig, ContainerClient, TaskDatasetSpec, TaskDescriptor, TaskInfo,
175    DEV_ENVIRONMENT_API_KEY_NAME, ENVIRONMENT_API_KEY_ALIASES_NAME, ENVIRONMENT_API_KEY_NAME,
176    MAX_ARTIFACTS_PER_ROLLOUT, MAX_ARTIFACT_CONTENT_TYPE_LENGTH, MAX_ARTIFACT_METADATA_BYTES,
177    MAX_CONTEXT_OVERRIDES_PER_ROLLOUT, MAX_CONTEXT_SNAPSHOT_BYTES, MAX_ENVIRONMENT_API_KEY_BYTES,
178    MAX_ENV_VARS, MAX_ENV_VAR_VALUE_LENGTH, MAX_FILES_PER_OVERRIDE, MAX_FILE_SIZE_BYTES,
179    MAX_INLINE_ARTIFACT_BYTES, MAX_TOTAL_INLINE_ARTIFACTS_BYTES, MAX_TOTAL_SIZE_BYTES,
180    PREFLIGHT_SCRIPT_TIMEOUT_SECONDS, SEALED_BOX_ALGORITHM,
181};
182
183// Re-export trace upload types
184pub use trace_upload::{TraceUploadClient, UploadUrlResponse};
185
186// Re-export utility helpers
187pub use utils::{
188    cleanup_paths, compute_import_paths, create_and_write_json, ensure_private_dir,
189    find_config_path, get_bin_path, get_home_config_file_paths, is_file_type, is_hidden_path,
190    load_json_to_value, repo_root, should_filter_log_line, strip_json_comments, synth_bin_dir,
191    synth_home_dir, synth_container_config_path, synth_user_config_path, validate_file_type,
192    write_private_json, write_private_text,
193};